#!/usr/bin/perl
#   sumcol [col1 [colN]] [file]...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# This reads the file[s] or stdin, splits the lines into columns, and  prints #
# out the sum of columns col1 thru colN (1 by default). Note that columns are #
# numbered from one, not zero.  Also, we throw away initial  white  stuff  so #
# that right-justified numbers (as from "ls -li") work right.                 #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$[ = $min = $max = 1;
if ($ARGV[1] =~ m/^\d/) {		# Ininial numeric arg?
	$min = $max = shift;		# Use it as the column number.
	if ($ARGV[1] =~ m/^\d/) {	# Another numeric arg?
		$max = shift;
}	}
while (<>) {	# Eat up the input.
	s/^\s+//;	# Strip out initial white space.
	split;		# Split into fields on white space.
	for ($col=$min; $col <= $max; $col++) {
		$sum[$col]  += $_[$col];
}	}
print "@sum	totals.\n";
