What I am attempting to do is write a perl script that reads the
sub-directories of the current directory, creates a menu bar with the
sub-directories as the titles of cascade widgets and then goes into the
sub-directories, read the files there and creates command widgets with
the file names as titles. For instance, if I have sub-directories
Algebra1 and Algebra2, each of which contains files Test1 and Test2,
then Algebra1 and Algebra2 appear in the menubar and clicking on them, I
get a drop down(?) menu with Test1 and Test2 command widgets appearing.
But, the script below does not work. I get an error message :
Not an ARRAY reference at
/usr/local/ActivePerl-5.6/lib/site_perl/5.6.1/i686-linux-thread-multi/Tk/Menu.pm
line 69. The cause of this is the subroutine sub_menu. As I understand
things, the argument to -menuitems must be a reference to an anonymous
array. Am I correct? Is there a way of getting sub_menu to return such a
value or is there another way to do this?
Thanks to all who read this post,
Dick Fell
#!/usr/local/ActivePerl-5.6/bin/perl5.6.1 -w
use strict;
use File::Basename;
use Tk;
use Tk::Dialog;
use Cwd;
our $MW =MainWindow->new();
&create_menu_bar;
MainLoop;
sub create_menu_bar
{
my $mb = $MW->Menu();
$MW->configure(-menu=>$mb);
opendir DIR, "./" or die " cannot open current directory: $!";
my $current_directory = cwd;
my @directories = grep { !/^\.\.?$/ && -d "$current_directory/$_" }
readdir DIR;
map {$mb->cascade(-label => '~'.$_, -menuitems=>\&sub_menu($_))}
@directories;
sub sub_menu
{
chdir "$_[0]" or die "Cannot change directory: $!"; # change to
Algebra1 sub-directory, then Algebra2, etc.
opendir SUB_DIR, "./" or die " cannot open current directory: $!";
my $current_sub_directory = cwd;
my @sub_directories = grep { !/^\.\.?$/ && -d
"$current_sub_directory/$_" } readdir SUB_DIR;
map {[ 'cascade', '~'.$_]} @sub_directories;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]