in reply to Question on arrays
So, it seems to me, you probably don't want to be adding or removing elements while within a for loop. Was that your question?If any part of LIST is an array, foreach will get very confused if you add or remove elements within the loop body, for example with splice. So don't do that.
For example, I just tested this w/ shift. I looped through an array using foreach and did a shift part of the way through:
Here's the output:my @arr = qw/foo bar baz quack/; for (@arr) { print $_, "\n"; shift @arr if $_ eq "bar"; }
So the shift shifted off "foo", which messed up the internal loop counter, which means that "baz" didn't get displayed. So this probably isn't the best idea.foo bar quack
|
|---|