in reply to Re(4) Whether to use local()
in thread Whether to use local()

Not according to the perl I use. The code below dies with Can't localize lexical variable $bar at pack.pl line 10.
#!/usr/bin/perl -w $main::foo = 'global'; my $bar = "my"; print "foo is ",$foo,"\n"; print "my is ",$bar,"\n"; { local $foo; local $bar; # Dies here. print "foo is ",$foo,"\n"; print "foo is ",$main::foo,"\n"; print "bar is ",$bar,"\n"; } print "foo is ",$foo,"\n"; print "my is ",$bar,"\n";


-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re(6) Whether to use local()
by dmmiller2k (Chaplain) on Mar 16, 2002 at 13:18 UTC

    My mistake, lexicals cannot be localized. However, pretty much everything else can (properties of objects, hash values and array elements, etc.).

    dmm