Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047053]
[Corion]: ... nope, it isn't
[LanX]: heh ... 11.78 popes per square mile ...never thought I might find miles handy
[ambrus]: TCLion: it's to make people write non-short writeups in an external editor and save it to a local file. otherwise people will complain that they had a very insightful extended reply but their browser died just when they were almost ready posting it.
[ww]: ++ambrus "their browser died just when...."
[ambrus]: ww: or they accidentally closed the window, or something. the exact excuse doesn't matter.
[ambrus]: you hear that on web forums frequently.
LanX Fermat 's famous browser

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2017-03-23 18:14 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (292 votes). Check out past polls.