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

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

by schwern (Scribe)
on Jun 05, 2006 at 19:01 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found