in reply to Array of hashes

use strict; use warnings; my ($outer_hash, $new_hash); $outer_hash->{backupsize} = [{ 'totalsize' => '89', 'hostname' => 'aaaa', 'application' => 'IDB' }, { 'application' => 'IDB', 'hostname' => 'aaaa', 'totalsize' => '32770' }, { 'application' => 'SAP', 'hostname' => 'bbbb', 'totalsize' => '14' }]; for my $entry(@{ $outer_hash->{backupsize} }){ next unless $entry->{hostname} and $entry->{application} and $entr +y->{totalsize}; $new_hash->{$entry->{hostname}} {$entry->{application}} += $entry- +>{totalsize}; } for my $h (sort keys %$new_hash){ print "HOST:$h:\n"; for my $app(keys %{ $new_hash->{$h}}){ print "\t",$new_hash->{$h}{$app},"\t$app\n"; } }
OUTPUT:
HOST:aaaa: 32859 IDB HOST:bbbb: 14 SAP

        "Software interprets lawyers as damage, and routes around them" - Larry Wall

Replies are listed 'Best First'.
Re^2: Array of hashes
by AnishaM (Acolyte) on Aug 22, 2016 at 07:27 UTC
    Thank you so much NetWallah :)