Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re(4) Whether to use local()

by shotgunefx (Parson)
on Mar 16, 2002 at 05:12 UTC ( [id://152159]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://152159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-19 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found