SPUG: IndexOf in Perl?

David Dyck david.dyck at fluke.com
Sat Jan 28 15:35:17 PST 2006


On Sat, 28 Jan 2006 at 15:16 -0800, Brian Wisti <brianwisti at yahoo.com> wrote:

> You might try the List::Util module. It's core in 5.8.
>
>  use List::Util qw(first);
>  ...
>  my $index = first { $_ == $test_value } @array;

$index is the element, not the index they were looking for.

perl -le ' use List::Util qw(first); print  first { /c/ } ('a' .. 'z'); '
c



More information about the spug-list mailing list