http://qs321.pair.com?node_id=553676


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.