in reply to •Re: Re: A man walks into a bar with a hash under each arm!
in thread Hash key intersection
Actually, it's important that you don't use keys in front of the individual hashes, otherwise alternate keys get used as values in the construction of the anonymous hash.
As I as showed, but with values added you get
@A{ qw[ 1 2 4 6 ] } = qw[ a b d f ]; @B{ qw[ 1 2 3 4 6 7 ] } = qw[ a b c d f g ]; print join '.', ( exists $A{ $_ } ? 'A:' . $_ : ' ' ), ( exists $B{ $_ } ? 'B:' . $_ : ' ' ) for sort keys %{ { %A, %B } }; A:1.B:1 A:2.B:2 .B:3 A:4.B:4 A:6.B:6 .B:7
But using the extra key statements you get
print join'.', ( exists $A{ $_ } ? 'A:' . $_ : ' ' ), ( exists $B{ $_ } ? 'B:' . $_ : ' ' ) for sort keys %{ { keys %A, keys %B } }; A:1.B:1 A:6.B:6 .B:7
|
|---|