in reply to Re^5: Analytics on Hash Arrays
in thread Analytics on Hash Arrays

Confused...My previous code just traverse till the end of DATA and just displays the end data. Its not performing what I am willing to do.

my $x=0; while(<DATA>){ next unless /\w/; my($server,$datetime,$metric,$value) = (split)[0,1,2,3]; $value =~ s/,//g ; my $ddhh = substr $datetime,0,13; my $dd = substr $datetime,0,10; $d{$dd }{$server}{$metric}{max} = ($x < $value) ? $value : $x; $d{$dd }{$server}{$metric}{min} = ($x > $value) ? $value : $x ; $h{$ddhh }{$server}{$metric}{max} = ($x < $value) ? $value : $x; $h{$ddhh }{$server}{$metric}{min} = ($x > $value) ? $value : $x ; $ser{$server} = 1; $met{$metric} = 1; }

In above code $x < $value always holds true and just traverse till end of DATA...it doesn't find the maximum value. If you don't mind can you please provide me the pseudo-code OR any hints to achieve it?

Replies are listed 'Best First'.
Re^7: Analytics on Hash Arrays
by MidLifeXis (Monsignor) on Jun 24, 2015 at 18:36 UTC

    Not code, but look at autovivication, defined, and exists. Basically, unless you set a variable to some value, it is undefined. defined allows you to test for that condition. If a min/max value is not defined when you first use it, would it not make sense to set them both to $value?

    --MidLifeXis