in reply to performance issues with grepping large sorted arrays
Two options. Build a lookup hash:
my %lu = map {$_ => 1} @array; foreach my $key (keys %H){ if ($lu{$key}) {
or turn the loop inside out:
foreach my $elt (@A){ if (exists $hash{$elt}) {
In the second case you may need to keep a record of hits so that you don't perform your hit process more than once (assuming that to be what you want).
Note that sorting the array will make no difference at all. grep always processes all elements. You could make a small efficiency gain by using a for loop instead of the grep and exiting as soon as a matching element is found.
|
|---|