Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my %original = ( a => 1, b => 2, c => 3, d => 4);
- my %subset = (e => 2, f => 4);
- # Doing a thing if keys are shared (or not, just invert)
- for $key (keys %original) {
- if( exists $subset{$key} ) {
- # shared key, do something
- ...
- if( $subset{$key} == $original{$key} ) {
- # shared key and value, do something
- ...
- }
- }
- }
- # Doing a thing if values are shared
- %original_values = reverse( %original )
- %subset_values = reverse( %subset )
- # now repeat the above loop, except note that if values aren't unique you will get a random key for it which might not match the random one chosen from the other hash and I don't know if that's important to you.
- # there are other solutions but I think this one spells it out most clearly.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement