[olug] One-liner adding machine

Jay Hannah jay at jays.net
Mon Feb 6 19:28:51 UTC 2006


Given a comma delimited file w/ numbers in the 3rd location, add up all
those numbers.

$ perl -anF',' -e '$total += $F[2]; print "$F[2] $total\n";' myfile.txt
| head
25000 25000
20946 45946
11592 57538
500 58038
500 58538
500 59038
500 59538
500 60038
500 60538
500 61038

Neat! Saved myself from having to write a 4 line program! -grin-

This is my first time using -a and -F. "perldoc perlrun" for more info.

Let's see your alternate syntaxii, shell gurus :)

j
Omaha Perl Mongers: http://omaha.pm.org





More information about the OLUG mailing list