Matthewl 发表于 2015-12-28 11:57:31

perl学习6-return操作符

  #!/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表示没有找到)
页: [1]
查看完整版本: perl学习6-return操作符