Straight from the perlsyn documentation:
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.
In your first function you are altering the array that you are iterating over with foreach inside the foreach block. This is not supported behaviour. The reason it doesn't happen in your second function is because you are altering a copy of the array.
- Cees
In reply to Re: for mistake with shift
by cees
in thread for mistake with shift
by hsmyers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |