in reply to Re^2: multiple hash compare, find, create
in thread multiple hash compare, find, create

Hello AnomalousMonk,

You are right. My solution after a bit of experimentation I can see that it is wrong. The best approach that I could think is similar to fellow Monk Eily.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; 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 %HoA; foreach my $key (keys %h1) { push(@{$HoA{$key}}, $h1{$key}, $h2{$key}, $h3{$key}) if exists $h2{$key} and exists $h3{$key}; } print Dumper \%HoA; __END__ $ perl test.pl $VAR1 = { 'b' => [ 2, 5, 6 ], 'a' => [ 1, 4, 12 ] };

Though Eily's approach is better using unless as it check if the hash exists if not skip not necessary to proceed and waste resources.

Thanks for spending the time to check and correct me :)

Seeking for Perl wisdom...on the process of learning...not there...yet!