Kelly Jones wrote:
If I do a for loop in a subroutine, do I have to declare it private
with my()? I always though for() did that for me, but I ran into a bug
where code like this:
sub foo {for $i (1..2) {print $i;}}
affected my global $i (I think). Or was I imagining it?
Probably, since $i ought to be implicitly localized to the loop.
http://perldoc.perl.org/perlsyn.html#Foreach-Loops
OTOH, I believe it's advisable to always my() declare loop variables,
even if there happens to be a global variable with the same name.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/