total

ziggy on 2002-03-10T19:17:17

TorgoX is performing a very valuable service by going through his collection of Perl scripts. Here's one I always carry with me - total:

#!/usr/bin/perl

use strict;
my $total;
while (<>) {
    $total += $_;
}

print "$total\n";
A very trivial script, but quite useful when you're trying to sum up a series of lines (from wc -l, du -k or somesuch) that start with a number on each line.