Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^4: Common hash keys

by tinita (Parson)
on Jun 08, 2008 at 12:11 UTC ( #690916=note: print w/replies, xml ) Need Help??

in reply to Re^3: Common hash keys
in thread Common hash keys

List::Util::first() returns the result of the code block, in this case the boolean return of the exists function.
i think it returns the key it's iterating over, just like grep works. from the docs: "first returns the first element where the result from BLOCK is a true value."
use List::Util qw[ first ]; my $a = { 0 => 0 }; my $b = { 0 => 0 }; if( first{ exists $b->{ $_ } } keys %$a ) { print "Common keys!"; }
prints nothing.

Replies are listed 'Best First'.
Re^5: Common hash keys
by BrowserUk (Patriarch) on Jun 08, 2008 at 15:51 UTC

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2022-05-17 14:37 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (66 votes). Check out past polls.