An alternative to your &find_first_index that I prefer (for smaller lists) is
I don't know about any efficiency issues though.use List::Util 'first'; sub find_first_index { my $target = shift; first { $_[$_] eq $target } 0 .. $#_; } # Simple enough to write inline: my $idx = first { $ary[$_] eq $target } 0 .. $#ary;
Update: Fixed a off-by-one bug in the sub and added parenthesis.
ihb
Read argumentation in its context!
In reply to Re^2: Common Perl Idioms
by ihb
in thread Common Perl Idioms
by eric256
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |