Perl是否具有内置函数来获取数组中元素的索引?还是我需要自己编写这样的函数? [等同于PHP array_search()或JavaScript array.indexOf()]
最佳答案
use List::Util qw(first);
$idx = first { $array[$_] eq 'whatever' } 0..$#array;
(列表:: Util是核心)
要么
use List::MoreUtils qw(firstidx);
$idx = firstidx { $_ eq 'whatever' } @array;
(列表:: MoreUtils在CPAN上)
关于perl - 如何获取数组中元素的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3222138/