#!/usr/bin/perl # # total # # AUTHOR: # Dan Harkless # # COPYRIGHT: # This file is Copyright (C) 2000 by Dan Harkless, and is released under the # GNU General Public License . # # DESCRIPTION: # Take a column of numbers on stdin and outputs their total on stdout. You # can also specify a list of filenames to operate on rather than stdin, if you # are so inclined. # # In the future I may modify it to also work with rows of numbers. Might also # be useful to specifically complain on stderr about non-numbers -- right now # they just don't contribute to the total. Also would be good if hex and # octal numbers were recognized. # # EXAMPLES: # % cut -d'"' -f3 access_log | cut -d' ' -f3 | total # % total list_A list_B list_C > lists_A-C_total # # DATE MODIFICATION # ========== ================================================================== # 2000-07-21 Original. $total = 0; while (<>) { $total += $_; } print "$total\n";