my @array; getreallyhugelist( \@array ); my @idxsToRemove= getnotashugelist(); my %toRemoveIdx; @toRemoveIdx{@idxsToRemove}= (1)x@idxsToRemove; @array= map { $toRemoveIdx{$_} ? () : $array[$_] } 0..$#array;
That last line copies the whole array once (puts it on the stack) and then only has to shift each non-removed element once. So it will probably be faster than repeated calls to splice() (each one having to shift the whole end of the array). I think this speed-up will more than compensate for the cost of building the hash (on the preceding line) if you are removing more than a few elements.
- tye (but my friends call me "Tye")In reply to Re: Removing certain elements from an array
by tye
in thread Removing certain elements from an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |