Iterating through the first hash and looking for keys that exist in the two other is enough.
But seeing the size of the input hashes, I'd say it might be better to do that while constructing the hashes (eg, first build %h1, then iterate through the values of %h2 but only insert the keys that already exist in %h1, and then the same for %h3), if they aren't tied hashes in the first place.use strict; use warnings; use Data::Dump 'pp'; my %h1 = ( a => 1, b => 2, c => 3, ); my %h2 = ( a => 4, b => 5, d => 10, ); my %h3 = ( x => 20, p => 15, b => 6, a => 12, ); my %out; for my $key (keys %h1) { next unless exists $h2{$key} and exists $h3{$key}; $out{$key} = [ $h1{$key}, $h2{$key}, $h3{$key} ]; } pp \%out; __END__ { a => [1, 4, 12], b => [2, 5, 6] }
In reply to Re^2: multiple hash compare, find, create
by Eily
in thread multiple hash compare, find, create
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |