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
In reply to combining hashes based on key values by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |