Sorry I was not clear with my requirement, also I made worst mistake in my code.
My requirement is to print the Maximum value the same way Average value printing works. So the assignment of values to hash array keys should be max value instead of sum of the values in that group.
while(<DATA>){
next unless /\w/;
my($server,$datetime,$database,$speed) = (split)[0,1,2,3];
my $ddhhmm = substr $datetime,0,16;
my $ddhh = substr $datetime,0,13;
$h{$ddhh }{$database} += $speed;
$m{$ddhhmm}{$database} += $speed;
$db{$database} = 1;
$sr{$server } = 1;
}
Is there a way to assign maximum value in this while loop shown above to $h{$ddhh }{$database} and $m{$ddhhmm}{$database} ??
If this is possible then I can follow the same procedure to print Max values the same way we did for Average.
One more doubt... All I did to find Average is to loop through the Hash Array one more time and assign the Average value to it as shown below
for my $key (sort keys %h){
for (@db) { $h{$key}{$_} = round($h{$key}{$_} / ($count * 60))} ;
}
Can it be done efficiently without looping the Hash Array again ? I mean can this be done in while loop itself ?
|