in reply to How to compute the avg of a column of numbers


Here is one way:
my $sum = 0; $sum += $_ for @total; my $average = $sum / @total;

And here is another:

my $average = 0; $average = ($_ * $average + $total[$_]) / ($_ + 1) for 0 .. @to +tal -1;

Or as a one-liner (for a space delimited file with the numbers in column 3):

perl -lane '$a = (($. -1) * $a + $F[2])/$.; END{print $a}' file

Or if the numbers are in the first column of the file:

perl -lpe '$,+=$_}{$_=$,/$.' file

--
John.