Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Efficient way to sum columns in a file

by dave0 (Friar)
on Apr 13, 2005 at 05:08 UTC ( #447268=note: print w/ replies, xml ) Need Help??


in reply to Efficient way to sum columns in a file

If you want to get rid of the 'cut', you can do it all in Perl using the -a and -F switches (see perlrun for details) to autosplit the input line into the @F array:

perl -lanF, -e '$sum += $F[6]; print "Sum is $sum" if eof' in.csv


Comment on Re: Efficient way to sum columns in a file
Download Code
Re^2: Efficient way to sum columns in a file
by sk (Curate) on Apr 13, 2005 at 05:44 UTC
    Thanks dave! I have never used aF switches before. I shall remember to use this instead of my  split/,/; However I am not sure if perl's split is more efficient than cut... I guess I can do a quick field test on a large file!

    -SK

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-03 17:52 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 (54 votes), past polls