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


In reply to Difference of Hash by Nansh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.