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.


In reply to Array of hashes by AnishaM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.