in reply to Re: Testing if an array contains a value and then deleting it in most efficient way
in thread Testing if an array contains a value and then deleting it in most efficient way
In code (while using array) ...
use List::MoreUtils qw/ firstidx /; for my $val ( generate() ) { my $i; # Deal w/ "uninitialized variable" warning as appropriate. while ( -1 < ( $i = firstidx { $_ == $val } @array ) ) { delete $array[ $i ]; } } # Later... # exists() here would go better with earlier delete(), but # then would need to generate list of indices. my @save = grep { defined $_ } @array;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Testing if an array contains a value and then deleting it in most efficient way
by ikegami (Patriarch) on Feb 18, 2008 at 16:30 UTC | |
by parv (Parson) on Feb 18, 2008 at 16:40 UTC | |
by ikegami (Patriarch) on Feb 18, 2008 at 16:50 UTC | |
by ikegami (Patriarch) on Feb 19, 2008 at 03:59 UTC | |
by parv (Parson) on Feb 19, 2008 at 08:49 UTC |