in reply to Accumulating Column Total From a CSV for a Common Key Value
Instead of:
$total{$appl} += $cpupct;
try:
$total{$server}->{$date}->{$appl} += $cpupct;
Then you'll just need to do three nested for loops to go through the three levels of the hash:
for my $server ( keys %total ){ for my $date ( keys %{$total{$server}} ){ for my $appl ( keys %{$total{$server}->{$date}} ){ printf $OUTCSV ("$server,$date,$appl,%3.1f%% \n", $total{$ +server}->{$date}->{$appl}); } } }
Update: code updated to correctly output total percentage.
Which will allow you to sum up the $cpupct by date and by server and will add those two columns to you output.
perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Accumulating Column Total From a CSV for a Common Key Value
by GeneV1 (Initiate) on Aug 30, 2007 at 12:30 UTC | |
by agianni (Hermit) on Aug 30, 2007 at 13:06 UTC | |
by GeneV1 (Initiate) on Sep 06, 2007 at 13:10 UTC |
In Section
Seekers of Perl Wisdom