Hi all,
What's the best way for creating a new hash which contains the difference between 2 other hases?
I have two hashes built like this:
$new_values{MachineType}{Blue_machine}{Unit}{1}{Channel}{0}{Value}{15}
$new_values{MachineType}{Blue_machine}{Unit}{1}{Channel}{1}{Value}{22}
$new_values{MachineType}{Blue_machine}{Unit}{2}{Channel}{0}{Value}{19}
$new_values{MachineType}{Red_machine}{Unit}{1}{Channel}{0}{Value}{22}
$old_values{MachineType}{Blue_machine}{Unit}{1}{Channel}{0}{Value}{14}
$old_values{MachineType}{Blue_machine}{Unit}{1}{Channel}{1}{Value}{22}
$old_values{MachineType}{Blue_machine}{Unit}{2}{Channel}{0}{Value}{21}
This should be the result:
$end_values{MachineType}{Blue_machine}{Unit}{1}{Channel}{0}{Value}{14}
$end_values{MachineType}{Blue_machine}{Unit}{2}{Channel}{0}{Value}{19}
$end_values{MachineType}{Red_machine}{Unit}{1}{Channel}{0}{Value}{22}
I could itterate over %new_values and compare the keys to %old_values and when they differ copy the thing over to end_values.
But when I have a key that exists in new_values and doesn't exist in old_values, then I would get an error. I could do an "if defined" first but this would bloat the whole thing.
Is there a Module which enables me to do so in a gracious way?
Thanks in advance!
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.