hiyall has asked for the wisdom of the Perl Monks concerning the following question:
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, }, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confused on handling merging values for hash of hashes
by LanX (Saint) on Feb 04, 2015 at 13:38 UTC | |
|
Re: Confused on handling merging values for hash of hashes
by hippo (Archbishop) on Feb 04, 2015 at 13:38 UTC | |
by Eily (Monsignor) on Feb 04, 2015 at 13:56 UTC | |
|
Re: Confused on handling merging values for hash of hashes
by choroba (Cardinal) on Feb 04, 2015 at 13:44 UTC | |
|
Re: Confused on handling merging values for hash of hashes
by shmem (Chancellor) on Feb 04, 2015 at 21:21 UTC | |
|
Re: Confused on handling merging values for hash of hashes
by locked_user sundialsvc4 (Abbot) on Feb 04, 2015 at 17:47 UTC |