in reply to Re: Making a match
in thread Making a match
Hashes certainly are the best solution, if you can amortize the set-up costs (and only slightly worse than grep even if you have to set up repeatedly -- i.e. if the list keeps changing).
But if ultimate efficiency is the goal, then there is an even more efficient way to use hash lookup:
my %hash; @hash{@list} = (); # Don't bother filling in values foreach my $x (1..1000) { if (exists $hash{$x}) # Just test for existence of key { print "$x is in the list\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Making a match
by DrManhattan (Chaplain) on Apr 14, 2003 at 10:40 UTC | |
by TheDamian (Vicar) on Apr 14, 2003 at 22:02 UTC | |
by TheDamian (Vicar) on Apr 14, 2003 at 22:43 UTC |
In Section
Seekers of Perl Wisdom