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?
[Lady_Aleena]: shmem, sorry I was outside for a moment moving my car out of hubby's way.
[Lady_Aleena]: shmem, there is ONE song which throws a wrench in the works for both MP3::Info and MP3::Tag.
[shmem]: Lady_Aleena: fix it, or delete it ;-)
[Lady_Aleena]: shmem, I'm not sure how.
[shmem]: well, deleting is done with 'rm' :-P

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-04-23 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.