#!/usr/bin/perl
# This does a sum and mean of a column of input.
# We need to figure out how to include a value of f on the command line.

if ($f < 1) {$f =  5;}
while (<>) {
	split;
#	print "Fields: `"; $, = "' `"; print @_; $, = ' '; print "'\n";
	$val = $_[$f];
	++$line;
#	printf("$#_=%d val=%5.2f\n",$#_,$val);
	if ($#_ > $f) {
		++$lines;
		$total += $val;
		printf("Line:%4d\tval=%5.2f\ttotal:%8.2f\tmean:%8.2f\t\n",
			$line, $val, $total, $total / $lines);
	} else {
		printf("Line %d has fewer than %d fields.\n",$line,$f);
	}
}
