in reply to Common hash keys
If the only thing you want is to know if they have some key in common:DB<1> %a = (a => 1, b =>2, c => 3); %b = (b =>2, c => 1, d => 4) DB<2> $seen{$_}++ for (keys(%a), keys(%b)) DB<3> x grep { $seen{$_} > 1 } keys(%seen) 0 'c' 1 'b'
Hope it helpsDB<1> use List::Util qw{first} DB<2> %a = (a => 1, b =>2, c => 3); %b = (b =>2, c => 1, d => 4) DB<3> x first { ++$seen{$_} > 1 } (keys(%a), keys(%b)) 0 'c'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Common hash keys
by FunkyMonk (Chancellor) on Jun 07, 2008 at 10:41 UTC | |
by lodin (Hermit) on Jun 08, 2008 at 06:32 UTC |