Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2015-11-27 22:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (734 votes), past polls