in reply to Re^3: Scalar Value Not Available To Subroutine
in thread Scalar Value Not Available To Subroutine
Effectively, the loop variable has no relationship with any pre-existing variable with the same name:
Same goes for local, fyi.
>perl -E"say 0+\$x; local $x; say 0+\$x;" 4885852 2403948
I've often wished (and occasionally argued in favour of), that for didn't localise pre-existing, lexical loop variables.
It would be useful and intuitive. It would drastically change the behaviour of the following, though
for $lex (...) { push @f, sub { ... $lex ... }; }
As it is now, I never use a pre-existing var.
|
---|
In Section
Seekers of Perl Wisdom