in reply to for mistake with shift
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: for mistake with shift
by hsmyers (Canon) on Dec 31, 2003 at 06:46 UTC |