http://www.perlmonks.org?node_id=1047053


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.