http://qs321.pair.com?node_id=690916


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