Now that you've explained what you want to do...
Take a look at splice. shift and pop remove values
from the ends of an array, not the current position. | [reply] |
From perlsyn section "Foreach Loops":
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.
As merlyn and tadman imply below, the "right" way to do it depends on what else you are doing in that chunk of code, and on your future use of @list (both pre- and post-modification).
| [reply] |