in reply to Foreach for array pruning?
I think I prefer your grep solution to the syntax you're asking for. Anyhow, the interior of for (@foo) {} doesn't know what position in the array $_ represents. You can do what you want with the indexes if you take them in reverse order to prevent splice from altering the yet-to-be-seen positions.
I imagine that all that splicing is less efficient than grep assignment. Notice that comparison with zero is unnecessary in the conditional.for (reverse 0 .. $#moo) { splice @moo, $_, 1 if $moo[$_] % 2; }
This is not too different from your C style loop, but corrects its major flaw.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Foreach for array pruning?
by demerphq (Chancellor) on Jul 02, 2004 at 21:46 UTC |