in reply to Re: Common Perl Idioms
in thread Common Perl Idioms
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Common Perl Idioms
by demerphq (Chancellor) on Jul 24, 2004 at 02:47 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2004 at 03:35 UTC |