Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
The stupid question is the question not asked
 
PerlMonks  

Re: local vs my

by JupiterCrash (Monk)
on Sep 02, 2002 at 14:56 UTC ( #194596=note: print w/ replies, xml ) Need Help??


in reply to local vs my

A difference between the 'my' function and the 'local' function that is not immediately obvious after reading their descriptions is illustrated by running the below snippet. It shows that 'my' is a bit more powerful, it keeps the variable's value completely within the block. While local allows calling subs to also access the variable's value within that block. Unless there are areas in your program that _expect_ this behavior, you should be fine changing everything to 'my'.

sub a { print "localVar is : $localVar \n"; print "myVar : $myVar \n" } sub b { local ($localVar); my ($myVar); $localVar = "I am localVar."; $myVar = "I am myVar."; &a; } # main &b;


Comment on Re: local vs my
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-04-18 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls