Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: what is the scope of my $x=$x

by schwern (Scribe)
on Jun 05, 2006 at 19:01 UTC ( #553676=note: print w/replies, xml ) Need Help??


in reply to what is the scope of my $x=$x

The real answer is "don't do that".

"my $x" and "$x" here are two different variables, there is nothing magical about them having the same name. "my $x" contains a copy of "$x". "my $x" exists only for the life of its scope and masks "$x". It should be clear now why you do not want to use the same variable name for an inner scope, the overlapping names make it really hard to remember what's going on or to even talk about it.

(local $x = $x is somewhat different)

Use a different name. Then it will become clear what the scope of each variable is and the issue goes away. I can't give you a good name without any context, and $x is an awful name to begin with, but even "my $copy_x = $x" is better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://553676]
help
Chatterbox?
[ambrus]: Corion: nice.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2016-12-08 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (139 votes). Check out past polls.