perldata monks,

I have

my %in_hash = ( jibber => [ {id => 1, score => 3, name => 'foo'}, {id => 5, score => 1, name => 'bar'}, {id => 22, score => 6, name => 'baz'}, ], jabber => [ {id => 3, score => 1, name => 'boo'}, {id => 5, score => 3, name => 'bar'}, {id => 12, score => 2, name => 'zib'}, {id => 22, score => 2, name => 'baz'}, ], );

and I want

my %out_hash = ( 'jibber jabber' => [ {id => 5, score => 4, name => 'bar'}, {id => 22, score => 8, name => 'baz'}, ], 'jibber' => [ {id => 1, score => 3, name => 'foo'}, ], 'jabber' => [ {id => 3, score => 1, name => 'boo'}, {id => 12, score => 2, name => 'zib'}, ], )

The %out_hash combines the entries in the incoming so that keys with common ids get their scores summed up, and other keys are left with the non-common id entries.

Monks that might ask what I have done thus far -- to them I spake, nothing more than constructing the above example hashes. Essentially, I am drawing a blank (other than doing some terrible, long-drawn, brute force method the very thought of which numbs me).

Update: Corrected the hash defs as per the most fascinating tlm

--

when small people start casting long shadows, it is time to go to bed

In reply to combining hashes based on key values by punkish

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.