Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Efficient way to sum columns in a file

by Roy Johnson (Monsignor)
on Apr 13, 2005 at 20:40 UTC ( #447580=note: print w/ replies, xml ) Need Help??


in reply to Re: Efficient way to sum columns in a file
in thread Efficient way to sum columns in a file

Although still slower than having separate variables for each column, this was a bit faster (and shorter) than your middle test:

time perl -nle'my $i=0;$a[$i++]+=$_ for (split/,/);END{print join "\t" +, @a}' numbers.csv
At only about 50% slower than the fastest solution, its brevity and adaptability might recommend it.

Caution: Contents may have been coded under pressure.


Comment on Re^2: Efficient way to sum columns in a file
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://447580]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2015-07-30 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls