To put it more succinctly,
There are three variables in scope with the same name (package var $foo aka $main::foo, the first lexical var $foo and the second lexical var $foo) so Perl needs to choose one to use. Perl always chooses the last one declared, falling back on the package var.
By the way, you would have gotten a warning.
Update: Fixed type in var name.
In reply to Re: Scope surprise
by ikegami
in thread Scope surprise
by smcdonald
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |