返回元素在数组中的索引值
上一篇 /
下一篇 2008-11-12 11:02:21
/ 个人分类:Perl
use warnings;
sub whichIs{
my ($str, @list) = @_;
foreach (0..$#list){
print $list[$_], "\n";
if ($str eq $list[$_]){
return $_;
}
}
-1;
}
my @names = qw / a b c fda wer fda fwefwkjl xxx dfao/;
my $wanna = "xxx";
print "\$wanna - $wanna is the ", &whichIs($wanna, @names), " of @names.\n";
#############################################################################
C:\Perl\learn>"which is.pl"
a
b
c
fda
wer
fda
fwefwkjl
xxx
$wanna - xxx is the 7 of a b c fda wer fda fwefwkjl xxx dfao.
收藏
举报
TAG:
Perl
array
element
index