Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.79 KB | None | 0 0
  1. my %original = ( a => 1, b => 2, c => 3, d => 4);
  2. my %subset = (e => 2, f => 4);
  3.  
  4. # Doing a thing if keys are shared (or not, just invert)
  5. for $key (keys %original) {
  6.     if( exists $subset{$key} ) {
  7.         # shared key, do something
  8.         ...
  9.         if( $subset{$key} == $original{$key} ) {
  10.             # shared key and value, do something
  11.             ...
  12.         }
  13.     }
  14. }
  15.  
  16. # Doing a thing if values are shared
  17. %original_values = reverse( %original )
  18. %subset_values = reverse( %subset )
  19. # 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.
  20.  
  21. # there are other solutions but I think this one spells it out most clearly.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement