in reply to How to compares 2 hashes and keep it in 3rd hash after that seggregate from array
Update
You may find this useful if I understand your question correctly:
use strict; use Data::Dumper; my %hash1 = ( 'key1' => '7', 'another_key' => '2', 'the third' => '8', ); my %hash2 = ( 'key1' => '7', 'another_key' => '2', 'the third' => "10", ); my @array = ('key1', 'data2'); # turning array into hash to do lookup inherently my %array_hash = map {$_, 1} @array; my %hash3; foreach (keys %hash1) { if ($hash1{$_} == $hash2{$_} && exists $array_hash{$_}) { $hash3{$_} = $hash1{$_}; } } print Dumper(\%hash3) . "\n";
|
|---|