in reply to HOW to calculate the column data
my %vals_by_type; while (<DATA>) { chomp; my ($type, $val) = split ' '; push @{ $vals_by_type{$type} }, $val; }
Then average each type individually
use List::Util qw( sum ); for my $type (sort keys %vals_by_type) { my $vals = $vals_by_type{$type}; my $avg = sum( map $_/@$vals, @$vals ); printf("%s %.2f\n", $type, $avg); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HOW to calculate the column data
by jwkrahn (Abbot) on Dec 03, 2009 at 21:18 UTC | |
by ikegami (Patriarch) on Dec 03, 2009 at 21:26 UTC |