in reply to rearrange data to min, avg, max
my $current_ts = ''; my $rowcount = 0; my ($min, $max, $sum, %ec); while (<>) { chomp; my ($ts, $v, $e) = split; if ($current_ts ne $ts) { if ($current_ts eq '') { $current_ts = $ts } else { &output_summary } $current_ts = $ts; ($min, $max, $sum) = ($v, $v, $v); %ec = ($e, 1); $rowcount = 1; } else { $min = $v if ($v < $min); $max = $v if ($v > $max); $sum += $v; ++$rowcount; ++$ec{$e}; } } &output_summary; sub output_summary { printf "%s\t%g\t%g\t%g\t%s\n", $current_ts, $min, $max, $sum/$rowcou +nt, join(',', keys %ec); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: rearrange data to min, avg, max
by Limbic~Region (Chancellor) on Apr 30, 2004 at 16:06 UTC |