|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re: Efficient way to sum columns in a fileby tlm (Prior) |
| on Apr 13, 2005 at 11:55 UTC ( #447331=note: print w/ replies, xml ) | Need Help?? |
|
By testing eof() instead of eof in dave0's one-liner, you can extend its functionality to sum across multiple files. Like this: What happens is that eof (no parens!) returns true at the end of each file in @ARGV, while eof() is true only at the end of the last one (see eof). In the case of a single input file, the behavior is the same as before. To get subtotals, you'd do
An alternative to testing for eof(), is to put everything in an END. e.g.
Update: Bug in last one-liner corrected. the lowliest monk
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||