Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2016-10-25 03:07 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.