use warnings; use strict; use List::Util qw(sum); my @list = (); while (<DATA>) { push @list, (split)[1]; } my $avg = (sum @list) / (scalar @list); print "Average: $avg\n"; 1; __DATA__ One 1 #First RedBaloons 99 #Second Normans 1066 #Third Thunderkiss 1965 #Fourth Warhammer 40000 #Fifth
I'm sure there's a CPAN module that'll do it even better, though. ;)
In reply to Re: How to compute the avg of a column of numbers
by Art_XIV
in thread How to compute the avg of a column of numbers
by cosmicsoup
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |