I think the following does everything you want. Going forward, please post real working code/data. Your hash references had to be completely reworked in order to demo them.

use warnings; use strict; my @a1 = ( { name => 'orange', fruit => 'yes', vegetable => 'no', count => 50 }, { name => 'squash', fruit => 'no', vegetable => 'yes', count => 10 }, ); my @a2 = ( { name => 'orange', fruit => 'yes', vegetable => 'no', count => 60, id =>123 }, { name => 'squash', fruit => 'no', vegetable => 'yes', count => 10, id => 222 }, ); my $count = 0; for my $first (@a1){ my $name = $first->{name}; my $second = $a2[$count]; for (keys %$second){ if (! exists $first->{$_}){ print "\@a2 has $_ for $name but \@a1 doesn't\n"; } } for my $k (keys %$first){ if (! exists $second->{$k}){ print "$k doesn't exist in \@a2 for $name\n"; next; } my $ne = 0; if ($first->{$k} =~ /^\d+$/){ if ($first->{$k} != $second->{$k}){ $ne = 1; } } else { if ($first->{$k} ne $second->{$k}){ $ne = 1; } } print "$k changed from $first->{$k} to $second->{$k} in $name\ +n" if $ne; } $count++; } } __END__ @a2 has id for orange but @a1 doesn't count changed from 50 to 60 in orange @a2 has id for squash but @a1 doesn't

In reply to Re: comparing 2 arrays of hashes by stevieb
in thread comparing 2 arrays of hashes by pearlgirl

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.