in reply to Re^2: Common hash keys
in thread Common hash keys
Actually, there's no need to be careful or test for definedness.
List::Util::first() returns the result of the code block, in this case the boolean return of the exists function. The values associated with the keys never come into it.
use List::Util qw[ first ];; my $a = { a=>0, b=>0, c=>0 }; my $b = { c=>0, d=>0, e=>0 }; if( first{ exists $b->{ $_ } } keys %$a ) { print "Common keys!"; } Common keys!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Common hash keys
by tinita (Parson) on Jun 08, 2008 at 12:11 UTC | |
by BrowserUk (Patriarch) on Jun 08, 2008 at 15:51 UTC |