Hello Nansh,

You need to show us at least that you tried to find a solution to your problem.

Your code does is not even correctly defined:

'Fruits'=> 'Apple', 'Orange', 'Banana', 'Grapes', , 'Fruits1'=> 'Apples', 'Orange', 'pineapple', 'Grapes',

When it should be like this:

#!/usr/bin/perl use strict; use warnings; my %HoA1 = ( Fruits => [ "Apple", "Orange", "Banana", "Grapes" ], ); my %HoA2 = ( Fruits1 => [ "Apples", "Orange", "pineapple", "Grapes" ], );

Help us to help you, read (How do I post a question effectively?)

A good starting point could be (Test::More):

#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; my %HoA1 = ( Fruits => [ "Apple", "Orange", "Banana", "Grapes" ], ); my %HoA2 = ( Fruits1 => [ "Apples", "Orange", "pineapple", "Grapes" ], ); is_deeply(\%HoA1, \%HoA2, 'data structures should be the same'); __END__ $ perl test.pl 1..1 not ok 1 - data structures should be the same # Failed test 'data structures should be the same' # at test.pl line 14. # Structures begin differing at: # $got->{Fruits1} = Does not exist # $expected->{Fruits1} = ARRAY(0xdc0bc8) # Looks like you failed 1 test of 1.

If you modify the keys to be the same e.g. "Fruits1" to "Fruits":

#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; my %HoA1 = ( Fruits => [ "Apple", "Orange", "Banana", "Grapes" ], ); my %HoA2 = ( Fruits => [ "Apples", "Orange", "pineapple", "Grapes" ], ); is_deeply(\%HoA1, \%HoA2, 'data structures should be the same'); __END__ $ perl test.pl 1..1 not ok 1 - data structures should be the same # Failed test 'data structures should be the same' # at test.pl line 14. # Structures begin differing at: # $got->{Fruits}[0] = 'Apple' # $expected->{Fruits}[0] = 'Apples' # Looks like you failed 1 test of 1.

Update: Based on your title of your question "Findidng Difference between two hash of arrays" you mean that you have two different hashes that contain array(s) inside. But based on your update of your question you probably mean that you have one hash with two arrays inside. This is why you should show us sample of your code and what you have tried so far.

Having said that sample of solution:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Array::Utils qw(:all); my %HoA = ( Fruits => [ "Apple", "Orange", "Banana", "Grapes" ], Fruits1 => [ "Apples", "Orange", "pineapple", "Grapes" ], ); # print Dumper \%HoA; =sample of Hash of Arrays output $VAR1 = { 'Fruits1' => [ 'Apples', 'Orange', 'pineapple', 'Grapes' ], 'Fruits' => [ 'Apple', 'Orange', 'Banana', 'Grapes' ] }; =cut my @AoAValues = sort values %HoA; # print Dumper \@AoAValues; =sample of Array of Arrays from values $VAR1 = [ [ 'Apple', 'Orange', 'Banana', 'Grapes' ], [ 'Apples', 'Orange', 'pineapple', 'Grapes' ] ]; =cut # get items from array @{$AoAValues[1]} that are not in array @{$AoAVa +lues[0]} # my @diff = array_minus( @{$AoAValues[1]}, @{$AoAValues[0]} ); my %hash; $hash{'difference'} = [ array_minus( @{$AoAValues[1]}, @{$AoAValues[0] +} ) ]; print Dumper \%hash; __END__ $VAR1 = { 'difference' => [ 'Apples', 'pineapple' ] };

I used Array::Utils module to compare the arrays, it has also some other features that you might be interested.

Update2: In case that you where trying to compare hashes of arrays as my initial impression try something like this:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Array::Utils qw(:all); my %HoA1 = ( Fruits => [ "Apple", "Orange", "Banana", "Grapes" ], Fruits1 => [ "WaterMellon" ], ); my %HoA2 = ( Fruits => [ "Apples", "Orange", "pineapple", "Grapes" ], Fruits1 => [ "Mellon" ], ); my @AoAValues1 = sort values %HoA1; my @AoAValues2 = sort values %HoA2; my %hash; for (0 .. $#AoAValues1) { $hash{$_} = [ array_minus( @{$AoAValues2[$_]}, @{$AoAValues1[$_]} +) ]; } print Dumper \%hash; __END__ $ perl test.pl $VAR1 = { '0' => [ 'Apples', 'pineapple' ], '1' => [ 'Mellon'

Hope this helps.

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

In reply to Re: Findidng Difference between two hash of arrays by thanos1983
in thread Findidng Difference between two hash of arrays 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.