in reply to deleting elements of one array from another
Use a hash slice to build a lookup table:
use strict; use warnings; my @db = (1, 3, 5, 7, 9, 11); my @in = (1, 2, 5, 8, 9, 10, 13); my %lookup; my @result; @lookup{@in} = (); foreach my $elem (@db) { push(@result, $elem) unless exists $lookup{$elem}; } print "@result\n"; # should print 3 7 11.
Of course, this doesn't actually remove the elements from @db. It creates a new array, @result, that holds only those elements of @db that were not also on @in. If your array is very, very large and you wish to avoid making a copy, this could be a problem.
|
---|