in reply to Question on arrays

I agree with btrott. Messing with the array elements is a Bad Idea(tm). It is absurdly easy to set up an infinite loop (or worse -- worse being subtle bugs rather than obvious bugs). I don't have a book handy, but from what I can tell by testing a few configurations, for and foreach both do implicit array operations that are, to the programmer, black-boxed. Don't mess with the box if you are new to perl.

The code btrott posts shows the implicit behavior. $_ is shifted/unshifted in every loop. Within the second loop, 'bar' is shifted from @arr into $_; as a result, the _explicit_ shift removes baz. When the loop ends, $_ is unshifted back onto the array but 'baz' is lost forever. @arr is reduced to 'foo bar quack'.

Of course, this could come in handy for obfuscation.