in reply to Compare array of hashes
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
|
|---|