I would probably use something like this.
The first foreach creates a hash that contains all of
the keys that are present in hash one and hash two
who's contents dont match. It's data element is a
list where $differences{$_}[0] is the data
from hash one and $differences{$_}[1] is the
data from hash two. It also has an entry for each key
in hash one that does not appear in hash two, where
$differences{$_}[1] is undefined.
The second foreach performs the inverse using the keys
of hash two. except that when a key in hash two is
not present in hash one, $differences{$_}[0]
is undefined and $differences{$_}[1]
contains the data from hash two. When it is complete
%differences contains 3 types of record:
- key appears in both hashes, but the data is
different.
- key appears in first hash, data in
$differences{$_}[0], $differences{$_}[1
] is undefined.
- key appears in second hash, data in
$differences{$_}[1], $differences{$_}[0
] is undefined.
my %differences = ();
foreach (keys %hash1) {
$differences{$_}= [$hash1{$_}, $hash2{$_}] if $hash1{$_} ne $hash2
+{$_};
};
foreach (keys %hash2) {
$differences{$_}= [$hash1{$_}, $hash2{$_}] if $hash1{$_} ne $hash2
+{$_};
};
Nuance
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.