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

Re^2: difference between my and local

by Eimi Metamorphoumai (Deacon)
on Nov 15, 2005 at 14:10 UTC ( #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.


    Free your mind

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2020-10-23 11:37 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (238 votes). Check out past polls.