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

Re: List::MoreUtils::first_value() question

by BrowserUk (Pope)
on Jul 30, 2013 at 15:15 UTC ( #1047053=note: print w/ replies, xml ) Need Help??


in reply to List::MoreUtils::first_value() question

In the first example, foobar is called on every list element, and first()'s economic magic is only applied to the defined operator. The second example demonstrates precisely the functionality I'm looking for.

Interpreting your question to mean that you want a list operator that short ciruits at teh first defined value it is passed, I think you are misinterpreting the results from both List::Util::first() & List::MoreUtils::first_value().

Both will short circuit if you test with defined (the use of grep is to demonstrate the contrast):

use List::Util qw[ first ];; use List::MoreUtils qw[ first_value ];; sub x{ say "<<<@_>>>"; return shift(); };; $x = grep{ defined( x($_) ) } 1, undef,3;; <<<1>>> Use of uninitialized value in join or string at (eval 17) line 1, <STD +IN> line 10. <<<>>> <<<3>>> $x = first{ defined( x( $_ ) ) } 1, undef, 3;; <<<1>>> $x = first_value{ defined( x( $_ ) ) } 1, undef, 3;; <<<1>>>

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: List::MoreUtils::first_value() question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-07-26 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls