I am in the middle of writing a script and have gotten stuck on an issue. I've been staring at this bit for so long and have made it so much more complicated than it should be that my brain now refuses to focus on it. It's like a giant mental blind spot. So I thought I'd come here and seek guidance through my darkness.

I have two arrays.
The elements of each array are references to anonymous hashes.
Each hash has 4 key/value pairs.

I'm comparing each hash in the two arrays looking for differences. If any single value in a hash is different I want the entire hash saved anonymously to the element of a new array and the key of the changed value should be "CHANGED."

Here's how I'm going through the arrays and hashes (and bears, Oh my!). (I realize this isn't very efficient. Any pointers how to make it more so would also be appreciated.)

use strict; foreach my $element1 (@array1) { foreach my $element2 (@array2) { foreach my $key (keys %{$element1}) { next if (%{$element1}->{$key} = %{$element2}->{$key}); ## OK Here's where the magic needs to happen. ## If there's a difference, I need the entire hash, %{$element1}, ## saved to the element of a new array with the "CHANGED" key in place } } }


I have prepared myself for enlightenment. (Nothing like a game to "clear the mind." :)

Thanks,
eclecticIO

"Given the pace of technology, I propose we leave math to the machines and go play outside."
Calvin - Homicidal Psycho Jungle Cat

In reply to Changing the keys of hashes in arrays by eclecticIO

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.