in reply to Re: Common hash keys
in thread Common hash keys
You can combine these two into a single statement:DB<2> $seen{$_}++ for (keys(%a), keys(%b)) DB<3> x grep { $seen{$_} > 1 } keys(%seen)
use Data::Dump; my %a = ( a => 1, b => 2, c => 3 ); my %b = ( b => 2, c => 1, d => 4 ); my %seen; pp grep { $seen{$_}++ } keys %a, keys %b;
Update: Don't use state variables for this. See lodin's reply
Or, with 5.10
pp grep { state %seen; $seen{$_}++ } keys %a, keys %b;
In Section
Seekers of Perl Wisdom