Nansh has asked for the wisdom of the Perl Monks concerning the following question:
I have an array
@arr= ("Fruit","Fruit1","Fruit3","Fruit4")
@arr1=("car","car1","car2","car3","car4")
My code is like this
#usr/bin/perl use Data::Dumper qw(Dumper); foreach $x(@arr) { I will do something and i will put something into an array called @v +al for each of the $x $hash{$x}=[@val]; } print Dumper \%hash; foreach $y(@arr1) { I will do something and i will put something into an array called @v +al2 for each of the $y $hash2{$x}=[@val2]; } print Dumper \%hash2; my %result; foreach $key(keys %hash1) { if(!exists $hash{$key}) { $result{$a}=$hash1{$key}; next; } foreach $new(keys %$key) { $result{$key}{$new}=$hash{$key}{$new} if(!exists $hash{$key}{$new} & +& $hash1{$key}{$new}) eq $hash{$key}{$new}); } } print Dumper \%result;
From above code i am not able to find the difference between two hash
I need to find the difference that is if the element is missing or element is extra in %hash1 it should show which element is missing or which element is extra when compared with %hash
It should check for both keys and values of the hash
please kindly help me to solve this i am strucked here
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Difference of Hash
by Eily (Monsignor) on Apr 06, 2017 at 10:12 UTC | |
by huck (Prior) on Apr 06, 2017 at 10:27 UTC | |
|
Re: Difference of Hash
by huck (Prior) on Apr 06, 2017 at 10:22 UTC | |
|
Re: Difference of Hash (reposts updated)
by LanX (Saint) on Apr 06, 2017 at 10:17 UTC | |
|
Re: Difference of Hash
by Discipulus (Canon) on Apr 06, 2017 at 10:24 UTC | |
|
Re: Difference of Hash
by thanos1983 (Parson) on Apr 06, 2017 at 11:08 UTC |