The variable $database is defined via my inside an if statement. Why can code outside of that block refer to it?
The closure that uses it should not be able to see into a parallel scope, as it only sees its enclosing things, right? Is there something funny about if statement blocks, or is this a perl bug, or what? The code works, and it's clear that the $database used by the subsequent code indeed is connected to Source Safe, so it's not finding a stray global.
baffled,
—John
Update: it no longer compiles, but gives the expected error. So why did it work once, on November 21? I hate anomolies.
Code attached,
sub go { print "Working area is \"$directory\"\n"; $version_text= "Iteration $version[0], " . ($version[2] ? "Revision $version[2]" : "initial release") . ($version[3] ? ", Patch $version[3]" : ""); print "Version stamp: $version_text\n"; if ($option eq 'checkout') { my $database; ###### DECLARE HERE $database= new Win32::OLE:: "SourceSafe"; my $copy= $source_safe_repository; # OLE doesn't like magic varia +bles $database->Open ($copy); } my $eachfile= sub { # on entry, $_ is name alone return unless /\.cxx$/ || /\.cpp$/ || /\.h$/ || /\.hpp$/; my $fname= $File::Find::name; $fname =~ tr[/][\\]; eval { process_file ($fname, $database); ##### USE HERE }; if ($@) { print "* An error was encountered processing \"$fname\". Error t +ext is:\n$@\n"; } }; my $filter= sub { return grep {$_ ne "Dependant_Libs" && !/\.OUT\./} @_; }; find ({wanted => $eachfile, preprocess => $filter}, $directory); print '=' x 50, "\n"; }
In reply to Something fishy about my scope by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |