Hello fellow monks, I can't use new modules in our environment( don't ask..), so I need to write the code from scratch. So the structure of array 1 is like so:
{ 'name' -> orange, 'fruit' -> yes, 'vegetable' -> no, 'count' -> 50 }, { 'name' -> squash, 'fruit' -> no, 'vegetable' -> yes, 'count' -> 10 }, etc..
array 2:
{'name' -> orange, 'fruit' -> yes, 'vegetable' -> no, 'count' -> 50 'id' ->123 }, { 'name' -> squash, 'fruit' -> no, 'vegetable' -> yes, 'count' -> 10 'id' -> 222 }, etc..

I need to compare the values of each hash element in the array, and print a difference if the count is different and for what , ex. Apples: was 20, now 30. ( That one I figured out how to do). And then if one has array has more/less elements I need to print something like : Added: Vegetable:beet, count: 20, etc, or removed: Fruit:apple, count 30, etc. I swear my brain just freezes on this one. I'm exhausted. The part that I figured out is below. That's when both arrays have the same number of elements, and I'm just pulling the count difference if any. Note: The array elements are in alphabetical order. array2 is a reference to an array of hashes ( to complicate things even further),

for ( my $i =0; $i <=$#array1; $i ++) { foreach my $key (sort keys %{$array2[$i]}){ if ($array1[$i]{$key} ne $$array2[$i]{$key}) { print "changes"; } } }
How do I do the other comparison when the number of keys is different? I hope I was clear, I hope someone can help.. Thank you!

In reply to 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.