Nikola -
Here is the code. I hope you can make some sense out of it. Thanks for
your efforts and help.
Dick
#!/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();
my $test_path="";
&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;
$mb->cascade(-label => '~'.$_, -menuitems=>&sub_menu($_)) foreach
(@directories); # creates Algebra1, Algebra2, etc menus
sub sub_menu
{
no warnings 'closure';
my $directory=$_[0];
my $current_directory = cwd."/$directory";
opendir SUB_DIR, $current_directory or die " In sub_menu cannot open
current directory: $!";
open LABEL_FILE, "$current_directory/label_file" or die "Cannot open
label file:$!";
# this file
contains a hash that associates the sub-directories with the label that
will
# appear in the
menu item. For instance, Expansion=>expanding expressions, etc.
my @sub_directories = grep { !/^\.\.?$/ && -d
"$current_directory/$_" } readdir SUB_DIR;
[map {[ 'cascade', $_, -menuitems=>&tests_menu($_,
$current_directory)]} @sub_directories]; # creates Factor, Expansion,
etc buttons
sub tests_menu # define this in sub_menu so I can access sub_menu's
local varibles. Creates command buttons for Test1, Test2, etc
{
my $tests_directory="$_[1]/$_[0]/Tests";
print "tests_directory is $tests_directory\n";
opendir TESTS_DIR, $tests_directory or die " cannot open Tests
directory: $!";
my @test_files = grep {-f "$tests_directory/$_"} readdir
TESTS_DIR;
print "tests_files is @test_files\n";
[map {[ 'command', $_,-command=>sub
{$test_path="$tests_directory"."/"."$_"; print "$test_path\n";}]}
@test_files];
}
}
}
Nikola Janceski wrote:
>
> how are using this subroutine in your code?
>
> Can you give us the line where you use this sub, Tk is bit picky at times
> when you try funky things.
>
> > -----Original Message-----
> > From: richard noel fell [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, April 23, 2002 10:45 AM
> > To: [EMAIL PROTECTED]
> > Subject: variable not set as expected
> >
> >
> > Below is a subroutine that is part of a perl/Tk script. The variable
> > $test_path is initialized earlier to the empty string and the variable
> > $tests_directory is likewise initialized to the correct directory. The
> > array @test_files contains entries such as (test1, test2, ..) and is
> > correctly set by the subroutine. The problem comes with -command=>sub
> > {$test_path="$tests_directory/$_"; print "$test_path\n";}
> > $test_path is
> > not set to $test_directory/test1, $test_directory/test2, but only to
> > $test_directory, as if @test_files were empty, which is not
> > the case.
> > Thanks for any advice,
> > Dick Fell
> >
> >
> > sub tests_menu
> > {
> > opendir TESTS_DIR, $tests_directory or die " cannot open Tests
> > directory: $!";
> > my @test_files = grep {-f "$tests_directory/$_"} readdir
> > TESTS_DIR;
> > [map {[ 'command', $_,-command=>sub
> > {$test_path="$tests_directory/$_";
> > print "$test_path\n";}]} @test_files];
> > }
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> ----------------------------------------------------------------------------
> --------------------
> The views and opinions expressed in this email message are the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]