in reply to Removing certain elements from an array
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")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Removing certain elements from an array
by mikfire (Deacon) on Aug 24, 2000 at 22:03 UTC | |
by tye (Sage) on Aug 24, 2000 at 22:16 UTC | |
by merlyn (Sage) on Aug 24, 2000 at 22:15 UTC | |
by mikfire (Deacon) on Aug 24, 2000 at 22:30 UTC | |
by lhoward (Vicar) on Aug 24, 2000 at 22:18 UTC | |
by tilly (Archbishop) on Aug 25, 2000 at 00:17 UTC |