Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: The difference between my and local

by Nazeerahamed (Initiate)
on Oct 06, 2012 at 16:15 UTC ( #997634=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

You can only localize a "package global variable" but not a lexical variable i.e., declared using "my". A package global can be created using "use vars qw($pkg_gbl_bar1 $pkg_gbl_bar2)". Please change your code as below
use strict;
use vars qw($tt);
$tt = 3.14159;
{
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";

Hope this helps you. If I am wrong, please let me know.
  • Comment on Re^4: The difference between my and local

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997634]
help
Chatterbox?
[choroba]: BTW, both the bands I play in performed on Friday (at the same event). Quite an exhausting experience.
[Corion]: choroba: Ooof! I can imagine that ;)
[Corion]: I think at a Perl workshop some years ago I gave two talks on the same day and after that decided to only submit one talk per event ;)
[LanX]: you play the triangle, right?

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-03-27 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (319 votes). Check out past polls.