在Perl中,如何在数组中找到给定值的索引?

前端之家收集整理的这篇文章主要介绍了在Perl中,如何在数组中找到给定值的索引?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
$VAR1 = [
          '830974','722065','722046','716963'
        ];

如何计算值“722065”的数组索引?

@H_404_7@解决方法
List::MoreUtils的firstidx功能可以帮助您:
use strict;
use warnings;
use List::MoreUtils qw(firstidx);

my @nums = ( '830974','716963' );
printf "item with index %i in list is 722065\n",firstidx { $_ eq '722065' } @nums;

__END__
item with index 1 in list is 722065
原文链接:https://www.f2er.com/Perl/172604.html

猜你在找的Perl相关文章