RosettaCodeData/Task/Search-a-list/Perl/search-a-list-2.pl
Ingy döt Net 86c034bb8b new files
2013-04-10 12:38:42 -07:00

13 lines
468 B
Perl

use List::MoreUtils qw(first_index);
my @haystack = qw(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo);
foreach my $needle (qw(Washington Bush)) {
my $index = first_index { $_ eq $needle } @haystack; # note that "eq" was used because we are comparing strings
# you would use "==" for numbers
if (defined $index) {
print "$index $needle\n";
} else {
print "$needle is not in haystack\n";
}
}