Hello Nansh,

It seems that you are doing your first steps in Perl just now. It would be very good for you to always use strict and warnings.

Now regarding your question, since I got the opportunity to answer on your previous question (Findidng Difference between two hash of arrays), I start to wonder if you really want to use Hashes of Arrays or simple perldata (hash/Subscripts).

When you have a hash you do care about the sequence of the keys in the hash, as long as you have the key you can compare keys. I think in you case you want to compare the fruits and find the difference. If this is the scenario (assuming because your description and approach is not clear) it can be done like this:

#!/usr/bin/perl use warnings; use strict; use Hash::Diff qw( diff ); use Data::Dumper qw(Dumper); my %hash; my @fruits = ("Fruit","Fruit1","Fruit3","Fruit4"); my @fruit_names = ("apple", "orange", "strawberry", "grape"); my @fruits_2 = ("Fruit","Fruit1","Fruit3","Fruit4"); my @fruit_names_2 = ("apple", "orange", "strawberry", "grapes"); # Approach one creating hash with 2 arrays for (0..$#fruits) { $hash{$fruits[$_]} = $fruit_names[$_]; } # print Dumper \%hash; # Approach two creating hash with 2 arrays my %hash_2; @hash_2{@fruits} = @fruit_names; # print Dumper \%hash_2; my %hash_3; @hash_3{@fruits_2} = @fruit_names_2; # print Dumper \%hash_3; my %hash_diff = %{ diff( \%hash_3, \%hash_2 ) }; print Dumper \%hash_diff; __END__ $ perl test.pl $VAR1 = { 'Fruit4' => 'grapes' };

Obviously the two hashes contain the same names and fruits apart from the plural on the second hash.

I hope this helps more.

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

In reply to Re: Difference of Hash by thanos1983
in thread 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.