AnishaM has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I have an array of hashes like this:
====
'backupsize' => [ { 'totalsize' => '89', 'hostname' => 'aaaa', 'application' => 'IDB' }, { 'application' => 'IDB', 'hostname' => 'aaaa', 'totalsize' => '32770' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '14' }, { 'totalsize' => '7444', 'hostname' => 'cccc', 'application' => 'MSSQL' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '7' }, { 'application' => 'WinFS', 'totalsize' => '1830535', 'hostname' => 'aaaa' }, { 'hostname' => 'dddd', 'totalsize' => '10240', 'application' => 'Oracle8' }, { 'application' => 'Oracle8', 'totalsize' => '1318400', 'hostname' => 'dddd' }, { 'application' => 'Oracle8', 'totalsize' => '680704', 'hostname' => 'dddd' }, { 'application' => 'IDB', 'hostname' => 'aaaa', 'totalsize' => '256' }, { 'hostname' => 'aaaa', 'totalsize' => '348', 'application' => 'IDB' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '4990' }, { 'hostname' => 'aaaa', 'totalsize' => '229', 'application' => 'IDB' }, { 'application' => 'SAP', 'totalsize' => '6', 'hostname' => 'bbbb' }, { 'totalsize' => '944171', 'hostname' => 'bbbb', 'application' => 'SAP' }, { 'application' => 'IDB', 'hostname' => 'aaaa', 'totalsize' => '113' }, { 'totalsize' => '14544', 'hostname' => 'bbbb', 'application' => 'SAP' }, { 'application' => 'IDB', 'totalsize' => '29758', 'hostname' => 'aaaa' }, { 'application' => 'Oracle8', 'totalsize' => '10129', 'hostname' => 'dddd' }, { 'totalsize' => '16385', 'hostname' => 'aaaa', 'application' => 'IDB' }, { 'application' => 'SAP', 'totalsize' => '542', 'hostname' => 'bbbb' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '861957' }, { 'hostname' => 'aaaa', 'totalsize' => '231', 'application' => 'IDB' }, { 'application' => 'IDB', 'hostname' => 'aaaa', 'totalsize' => '260' }, { 'application' => 'Oracle8', 'hostname' => 'dddd', 'totalsize' => '4565' }, { 'hostname' => 'bbbb', 'totalsize' => '19534', 'application' => 'SAP' }, { 'hostname' => 'aaaa', 'totalsize' => '594', 'application' => 'IDB' }, { 'totalsize' => '1566381', 'hostname' => 'bbbb', 'application' => 'FileSystem' }, { 'application' => 'Oracle8', 'totalsize' => '256', 'hostname' => 'dddd' }, { 'totalsize' => '78', 'hostname' => 'bbbb', 'application' => 'SAP' }, { 'hostname' => 'aaaa', 'totalsize' => '104', 'application' => 'IDB' }, { 'totalsize' => '4620', 'hostname' => 'aaaa', 'application' => 'IDB' }, { 'hostname' => 'aaaa', 'totalsize' => '24011', 'application' => 'IDB' }, { 'hostname' => 'aaaa', 'totalsize' => '24694', 'application' => 'IDB' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '2054983' }, { 'totalsize' => '559', 'hostname' => 'bbbb', 'application' => 'SAP' } ]
====
I want to write perl code which would iterate through my array of hashes, and look for - if same hostname and application exists then it should add the total size.
My new array of hashes should contain only 1 entry for each hostname and application.
Could anyone please help?
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of hashes
by NetWallah (Canon) on Aug 19, 2016 at 14:33 UTC | |
by AnishaM (Acolyte) on Aug 22, 2016 at 07:27 UTC | |
|
Re: Array of hashes
by stevieb (Canon) on Aug 19, 2016 at 13:17 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2016 at 16:14 UTC |