in reply to Need a replacement method for older version of perl
Using first might not be a great idea. If $curEntry is the empty string "", and @taxR does actually contain an empty string (so you should expect a match), then first will end up returning false.
The any function from List::MoreUtils is probably a better choice.
As to your question, you might get better performance from a hash:
my @taxR = ("PLRV1", "PMTVS", "PVXHB"); # Copy the array into a hash. # Make sure you only do this once. my %taxR = map {$_ => 1} @taxR; my $curEntry = "PMTVS"; if (exists $taxR{$curEntry}) { print "do rest of stuff"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need a replacement method for older version of perl
by vivomancer (Initiate) on Jun 26, 2012 at 23:30 UTC |