Next | Welcome to my ~/bin | 9 |
#!/usr/local/bin/perl -na BEGIN { $fieldno = shift } $total += defined($fieldno) ? (split(/\s+/))[$fieldno-1] : $_;
END{print $total, "\n" }
Some things to notice here
I forgot about -a and @F, and used split again
$fieldno-1 means that addup 1 adds up the first column
It doesn't work for negative arguments
The code is really sloppy
In a 3-line program, who cares?
Next | Menu | Copyright © 2005 M. J. Dominus |