Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: normal array exists question

by JanneVee (Friar)
on Jul 21, 2004 at 18:27 UTC ( #376349=note: print w/replies, xml ) Need Help??

in reply to Re: normal array exists question
in thread normal array exists question

Question: the List::Utils first, does do a linear scan for the first element that matches?

Replies are listed 'Best First'.
Re^3: normal array exists question
by Limbic~Region (Chancellor) on Jul 21, 2004 at 19:34 UTC
    The tutorial covers a bit of this, but I will go into more depth here. List::Util's first is designed to generic and portable. It is prototyped to $@ where the first argument is the code reference that will be applied to the remaining items in the list. It starts at the beginning and returns as soon as the code ref evaluates to true. This does not need to be an exact match as you could use a regex in block for instance. It does have a couple of issues with regards to efficiency.
    • It does not provide ability to pass by reference so the @_ stack of aliases has to be generated. This can be costly on large lists
    • The code reference has to be dereferenced for each item in the list until a match is found.
    Now you can roll your own to be more efficient but that defeats the purpose of having portable re-useable code. Additionally, shaving a second or two off of run time is seldom worth the programmer time required to achieve it.

    Cheers - L~R

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://376349]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2021-09-26 13:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found