in reply to Simple Totals Example (Help Needed)
Here's a "one liner" solution:
perl -naF, -e "$t += $F[1]; eof and print $t;" siteperf.txt
If you wrote that out "the long way", here's how it would look:
while ( <> ) { @F = split ','; $t += $F[1]; eof and print $t; } # Usage: perl mytally.pl siteperf.txt
Within the one-liner, the -n flag is responsible for creating a while( <> ) {.... loop. The -a flag is responsible for creating a @F = split ','; statement. And because the -n loop wraps a loop around all the code, a test must be conducted to spot the end of the file, and print the resulting tally only on the last loop iteration.
Can anyone golf the one liner down to fewer keystrokes than this?
perl -naF, -e"$t+=$F[1];eof&&die$t" test.txt
(44, including filename. Choosing a shorter filename doesn't count.)
Dave
|
|---|