RE: variable not set as expected

2002-04-23 Thread Timothy Johnson

 
Have you tried doing a print @test_files;?  It looks to me like there
wouldn't be any files in the array because readdir(TESTS_DIR) would return
only the file names, not the full paths, so grep {-f $tests_directory/$_}
readdir TESTS_DIR; might not be returning anything.  But then again I'm not
a huge grep user, so I could be wrong.

-Original Message-
From: richard noel fell
To: [EMAIL PROTECTED]
Sent: 4/23/02 7:44 AM
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]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: variable not set as expected

2002-04-23 Thread richard noel fell

Timothy -
Yes, I have done a print @test_files and it is as expected.
Dick


Timothy Johnson wrote:
 
 
 Have you tried doing a print @test_files;?  It looks to me like there
 wouldn't be any files in the array because readdir(TESTS_DIR) would return
 only the file names, not the full paths, so grep {-f $tests_directory/$_}
 readdir TESTS_DIR; might not be returning anything.  But then again I'm not
 a huge grep user, so I could be wrong.
 
 -Original Message-
 From: richard noel fell
 To: [EMAIL PROTECTED]
 Sent: 4/23/02 7:44 AM
 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]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: variable not set as expected

2002-04-23 Thread Nikola Janceski

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]




Re: variable not set as expected

2002-04-23 Thread richard noel fell

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]




RE: variable not set as expected

2002-04-23 Thread Nikola Janceski

I can't make sense of the code. Sorry, but this is what I see looking back..

[map {[ 'command', $_,-command=sub{$test_path=$tests_directory./.$_;
print $test_path\n;}]}@test_files];

This line... you will understand if broken up by some white space

[
map {
[ 'command', 
$_,
-command=sub{$test_path=$tests_directory./.$_; 
print $test_path\n;}
]
}
@test_files
];

Notice how you created an anonymous subrouting with $_ in it?
sub{$test_path=$tests_directory./.$_; 
print $test_path\n;}


Well... $_ doesn't get changed to its current value at that point in your
program.
$_ will be whatever $_ is when you actually run the anonymous subroutine.

Remember when writing subroutines, especiallly anonymous ones, that are used
by Tk, they don't get evaled until the subroutine is called.

maybe someone can tell me if I am right, but wouldn't he need to do
something like this?:

sub{$test_path= eval{$tests_directory./.$_} 
print $test_path\n;}

-Nik





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]




Re: variable not set as expected

2002-04-23 Thread richard noel fell

Nikola -
An interesting point. Perhaps you are onto something, but an eval where
you suggested does not work. However, you comments lead me to other
ideas to try.
Thanks,
Dick



Nikola Janceski wrote:
 
 I can't make sense of the code. Sorry, but this is what I see looking back..
 
 [map {[ 'command', $_,-command=sub{$test_path=$tests_directory./.$_;
 print $test_path\n;}]}@test_files];
 
 This line... you will understand if broken up by some white space
 
 [
 map {
 [ 'command',
 $_,
 -command=sub{$test_path=$tests_directory./.$_;
 print $test_path\n;}
 ]
 }
 @test_files
 ];
 
 Notice how you created an anonymous subrouting with $_ in it?
 sub{$test_path=$tests_directory./.$_;
 print $test_path\n;}
 
 Well... $_ doesn't get changed to its current value at that point in your
 program.
 $_ will be whatever $_ is when you actually run the anonymous subroutine.
 
 Remember when writing subroutines, especiallly anonymous ones, that are used
 by Tk, they don't get evaled until the subroutine is called.
 
 maybe someone can tell me if I am right, but wouldn't he need to do
 something like this?:
 
 sub{$test_path= eval{$tests_directory./.$_}
 print $test_path\n;}
 
 -Nik
 
 
 
 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]