in reply to Re^2: Any easy way to do this?
in thread Any easy way to do this?

Note the correction to my code snippet -- if $i were lexically scoped in the "for" statement (as originally posted), it would be unavailable after exiting that loop.

Replies are listed 'Best First'.
Re^4: Any easy way to do this?
by GrandFather (Saint) on Sep 16, 2011 at 07:57 UTC

    That must have been an ENOCOFFEE error! Consider:

    use strict; use warnings; my $i = "Nothing to see here, move along\n"; for $i (1 .. 3) { print "$i "; } print $i;

    Prints:

    1 2 3 Nothing to see here, move along

    The for loop variable is aliased to the elements in the for list. Any global (to the loop) variable that happens to have the same name is unaffected by the loop and, in particular, does not end up with the last contents of the loop variable!

    True laziness is hard work