nzgrover has asked for the wisdom of the Perl Monks concerning the following question:
... ordered by the "id" fields. I wish to find the hashes with duplicate "id"s and "merge" them together. That is, if there are two (or more) Hashes with the same "id"s, I want to add the "value"s together and remove the duplicate Hashs. So with the input data given above, the resultant data would look like:var = [ { 'id_a' => '1', 'id_b' => '5', 'value_x' => '10' 'value_y' => '5' }, { 'id_a' => '2', 'id_b' => '3', 'value_x' => '20' 'value_y' => '10' }, { 'id_a' => '2', 'id_b' => '3', 'value_x' => '30' 'value_y' => '20' }, { 'id_a' => '3', 'id_b' => '7', 'value_x' => '15' 'value_y' => '15' } ]
Any ideas?var = [ { 'id_a' => '1', 'id_b' => '5', 'value_x' => '10' 'value_y' => '5' }, { 'id_a' => '2', 'id_b' => '3', 'value_x' => '50' 'value_y' => '30' }, { 'id_a' => '3', 'id_b' => '7', 'value_x' => '15' 'value_y' => '15' } ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Messing about in Arrays of Hashes
by graff (Chancellor) on Sep 21, 2004 at 03:37 UTC | |
by nzgrover (Scribe) on Sep 21, 2004 at 04:35 UTC | |
|
Re: Messing about in Arrays of Hashes
by bobf (Monsignor) on Sep 21, 2004 at 04:06 UTC | |
|
Re: Messing about in Arrays of Hashes
by tachyon (Chancellor) on Sep 21, 2004 at 03:53 UTC | |
|
Re: Messing about in Arrays of Hashes
by Errto (Vicar) on Sep 21, 2004 at 03:44 UTC | |
|
Re: Messing about in Arrays of Hashes
by graff (Chancellor) on Sep 21, 2004 at 03:56 UTC | |
by nzgrover (Scribe) on Sep 21, 2004 at 04:37 UTC | |
|
Re: Messing about in Arrays of Hashes
by TedPride (Priest) on Sep 21, 2004 at 08:00 UTC | |
by TedPride (Priest) on Sep 21, 2004 at 08:08 UTC |