Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-12-28 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls