References to good books or urls covering this issue will be appreciated.
I am new to Perl and confused a bit by hash of hashes, array of hashes:
Given the following %HOH:
# the key field is an arbitrary int that needs to be unique - it serves no purpose other than to provide a unique key for the hash
%HOH = [ { key => 1, person => "Mike", possession => "wallet, keys, car, house", age => 25, }, { key => 2, person => "Mike", possession => "dog, cat, baseball bat", age => 25, }, { key => 3, person => "Dave", possession => "pony, house, car, keys", age => 21, }, ];
How would one consolidate the hash of hashes to another hash of hashes or array of hashes so that if person and age were same, the possession would be a merge of the possession ... resulting in one entry per person/age combination but with all possessions in the array(list) of values for the possession key?
The desired result is:or%HOH = [ { key => 1, person => "Mike", possession => "wallet, keys, car, house, dog, cat, baseball bat" +, age => 25, }, { key => 3, person => "Dave", possession => "pony, house, car, keys", age => 21, }, ];
@AOH = ( { person => "Mike", possession => "wallet, keys, car, house, dog, cat, baseball bat" +, age => 25, }, { person => "Dave", possession => "pony, house, car, keys", age => 21, }, );
In reply to Confused on handling merging values for hash of hashes by hiyall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |