Hi AnishaM,

We are really trying to help you help yourself. Marshall provided a good suggestion for making sure your data is what you think it is. Take a look at the following code for examples of inspecting your complex data structure. It really does help to clean up your code, indent properly, and be consistent. I have changed your original data slightly by making all the numbers be numbers instead of a mix of strings and numbers, and all the strings be not barewords. Note the usage of use strict; and use warnings; at the top.

use strict; use warnings; use Data::Dumper; my %HOAOH1 = ( 'details' => [ { 'name' => 'bbbb', 'time' => 1234, 'place' => 'AB' }, { 'name' => 'aaaa', 'time' => 5678, 'place' => 'CD' }, { 'name' => 'aaaa', 'time' => 91011, 'place' => 'EF' }, { 'name' => 'aaaa', 'time' => 121314, 'place' => 'GH' }, { 'name' => 'cccc', 'time' => 151617, 'place' => 'IJ' }, ] ); print Dumper \%HOAOH1; # See how useful Data::Dumper is for debugging +hashes and more complex data structures? print $HOAOH1{'details'}; # Do you see why this just prints an array r +eference? print "\n"; print @{$HOAOH1{'details'}}; # Do you see why this just prints a bunch + of hash references? print "\n"; foreach my $hash_reference (@{$HOAOH1{'details'}}) # Do you see how th +is loop is accesing the lowest level hash keys and values? { # Do you see the two different ways of de-referencing used here? print "$_=$$hash_reference{$_} " foreach (sort keys %{$hash_refere +nce}); print "\n"; }

You could also look at the following for help learning as well:

http://perldoc.perl.org/perldsc.html#Declaration-of-a-HASH-OF-COMPLEX-RECORDS

http://docstore.mik.ua/orelly/perl4/prog/ch09_03.htm

I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

In reply to Re: Compare array of hashes by perldigious
in thread Compare array of hashes by AnishaM

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.