in reply to Re^2: reuse of split variable?
in thread reuse of split variable?

True in perl also, but only in nooks and crannies. Compare these three:
$ perl -we'@foo = 1..10; for (@foo) { delete $foo[10-$_] } print scala +r @foo' 5 $ perl -we'@foo = 1..10; for (my @bar=@foo) { delete $foo[10-$_] } pri +nt scalar @foo' 0 $ perl -we'@foo = 1..10; for (@foo,()) { delete $foo[10-$_] } print sc +alar @foo' Use of freed value in iteration at -e line 1.

Replies are listed 'Best First'.
Re^4: reuse of split variable?
by Anonymous Monk on Nov 11, 2004 at 23:10 UTC

    Very interesting ....

    Did you know where to look for this kinds of things?
    Where are they documented?
    Apart from www.perlmonks.com of course

    Thanks, as we say is Spain (proverb), "you'll never go to sleep without knowing something new".
    I've discovered what a nook and a crannie are

      I read bug reports as they come in. Problems from messing with the array that for is looping over is a common theme.