in reply to Re: The most efficient way for searching for an element in an array?
in thread The most efficient way for searching for an element in an array?
Right track, but still too much work being done in the loop!
my @choices = qw/Apple Banana Tiger Lion Cat Turtle/; my @Single = qw/Apple Turtle/; my @Double = qw/Lion/; my %flags = ( map { $_ => 1 } @Single ), ( map { $_ => 2 } @Double ); for my $choice (@choices) { my $flag = $flags{$choice} || 0; print "$choice => $flag\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: The most efficient way for searching for an element in an array?
by Anonymous Monk on Jan 10, 2016 at 19:04 UTC |