in reply to How can I delete an element in a foreach cycle?
TIMTOWTDI. You could remember the indices and splice the goners out, highest first:
my @goners; for (0 .. $#ARGV) { unshift @goners, $_ if $ARGV[$_] eq 'hello'; } splice @ARGV, $_, 1 for @goners;
update: $#ARGV instead of @ARGV-1 as per dsheroh's comment below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I delete an element in a foreach cycle?
by dsheroh (Monsignor) on Feb 27, 2010 at 11:10 UTC | |
by shmem (Chancellor) on Feb 27, 2010 at 11:29 UTC | |
by ikegami (Patriarch) on Mar 01, 2010 at 03:43 UTC | |
|
Re^2: How can I delete an element in a foreach cycle?
by jasonk (Parson) on Mar 02, 2010 at 04:35 UTC |