John Deighan wrote:
>> OK, then, consider this program. Notice that there's a global $i which 
>> has the value 5. Now, when func() is called, if the "my $i" did not 
>> create a new lexically scoped variable, then the print line would print 
>> "i = 5". But it doesn't - obviously because the lexical variable was 
>> created, but is undefined because $b is false.
>> 
>> our $i = 5;
>> our $b = 0;
>> 
>> func();
>> 
>> sub func {
>> 
>> my $i = 3 if $b;
>> print("i = $i\n");
>> }

Here's a modification of that that illustrates the problem:

$i = 5;
func();
print("1: i = $i\n");
func();
print("2: i = $i\n");
sub func {
        print("before my: i = $i\n");
        my($i) = 3 if undef;
        print("after my: i = $i\n");
        $i = 7;
        print("after =: i = $i\n");
}
################
before my: i = 5
after my: i =
after =: i = 7
1: i = 5
before my: i = 5
after my: i = 7
after =: i = 7
2: i = 5

So u see, it's after u utilize the my twice that things veer off into the
twilight zone.  I believe this is another side effect of the not fully
developed closure syntax.  The my statement is only partially doing it's
thing.  The $i=7 value should have gone out of scope when func returned but
it didn't, it stayed alive after the indeterminate my.  U have this thing
for excessivly convoluted code. ;)





--
REMEMBER THE WORLD TRADE CENTER         ---=< WTC 911 >=--
"...ne cede malis"

00000100

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to