I have two hashes
%hash1,%hash2 - each one of them has a key (represents the path) and a value (represents a numeric value).
I would like to merge those two hashes into one main hash so every main hash key is the sum of the two values (of the same keys).
if $key1 of %hash1 with value1 is equal to $key2 of %hash2 with value 2 then the value of %main_hash{$key1} is value1+value2.
How should I do it? I already checked that the value is numeric so no need to check. Looking for the best-shorted way :)
EDIT: sorry If my question was hard to understand. Each one of the hashes can containe keys that the other hash doesn't have. I think I know how to implement it by a function but I was wondering if there is a better, good looking, less coded way.
Again, sorry for not explaining the question enough.
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.