Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: difference between my and local

by Eimi Metamorphoumai (Deacon)
on Nov 15, 2005 at 14:10 UTC ( [id://508617]=note: print w/replies, xml ) Need Help??


in reply to Re: difference between my and local
in thread difference between my and local

I'm not quite sure what you're getting at, but you can certainly get the global value from anywhere, without using local. Observe:
# main scope $fred = 1; #global { # outer scope my $fred = 2; #... { #inner scope print $main::fred; # prints the global 1 } }
The best rule of thumb is to use my unless you have some particular reason to use something else.

Replies are listed 'Best First'.
Re^3: difference between my and local
by Moron (Curate) on Nov 15, 2005 at 14:26 UTC
    You'll find that my is used more often than local. So what I am getting at is that whereas my $fred = $fred will have the same effect as local $fred most of the time, it won't always. I expect the OP to wonder why he ever needs local instead of just using my $fred = $fred rather than to wonder why he needs my - he already knows why he needs my and he already knows broadly what both of these do.

    -M

    Free your mind

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found