in reply to finding index number in an array

anything you do (besides List::Util first) will be "just as bad" as a foreach, because you'll have to loop through - even a grep is just a loop

The bonus of "first" is that it is executed in a subroutine and can return immediately when it finds the first instance.

Replies are listed 'Best First'.
Re^2: finding index number in an array
by fishbot_v2 (Chaplain) on May 27, 2005 at 22:54 UTC

    The additional bonus of List::Util::first() is that it is compiled, so you will get performance akin to grep.

    I wrote a myfirst using for that shortcircuits like List::Util:

    Rate myfirst first myfirst 875/s -- -83% first 5236/s 498% --

    More interesting, possibly, is a comparison of grep and first solutions - does the slight overhead of calling first (a compiled, but still user, function) out-weight the benefit?