Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194596]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2018-07-22 04:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (451 votes). Check out past polls.

    Notices?