http://www.perlmonks.org?node_id=250052


in reply to Making a match

If you're checking $x aginst your list multiple times, it might be more efficient to use a hash:
my @list = (10,11,12,13,14,15,17,18,22,23,24,25,26,27,28,29,30,31,32,3 +3,34,35 ); my %hash; @hash{@list} = (1) x @list; # This solution only makes sense if you're # making the comparison multiple times foreach my $x (1..1000) { if ($hash{$x}) { print "$x is in the list\n"; } }
You spend some initial setup time creating the hash, but then all your comparisons are O(1).

-Matt