Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: The difference between my and local

by ikegami (Pope)
on Oct 17, 2006 at 15:11 UTC ( #578803=note: print w/ replies, xml ) Need Help??


in reply to Re^3: The difference between my and local
in thread The difference between my and local

As you've already been told (by Perl and by fellow monks), you can't use local on a lexical (my) variable.

Fellow monks have shown how you can achieve your goal using my instead of local. If you had to use local, then you need to make a package variable by that name first.

use strict; my $tt = 3.14159; { our $tt; local $tt = 3; print "In block, \$tt = $tt\n"; print "In block, \$::tt = $::tt\n"; } print "Outside block, \$tt = $tt\n"; print "Outside block, \$::tt = $::tt\n";

You should never have to use this, though. Always use my if possible.


Comment on Re^4: The difference between my and local
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-07-04 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls