#!/usr/bin/perl -w
my @names=qw/ fred barney betty dino wilma pebbles bamm-bamm /;
my $result=&which_element_is("dino",@names);
sub which_element_is {
my($what,@array)=@_;
foreach (0..$#array) {
if ($what eq $array[$_]) {
return $_;
}
}
-1;
}
print "The position is $result\n";
查找单词位于第几个(-1表示没有找到)