Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: adding a column of integers

by ambrus (Abbot)
on Jun 26, 2006 at 18:25 UTC ( [id://557632]=note: print w/replies, xml ) Need Help??


in reply to adding a column of integers

This ruby solution also deserves a mention as it doesn't slurp the file thanks to ruby iterators.

ruby -we 'puts $<.inject(0) {|a, x| a + x.to_i };'

Replies are listed 'Best First'.
Re^2: adding a column of integers
by ikegami (Patriarch) on Jun 26, 2006 at 18:30 UTC

    perl -lne '$sum+=$_; END{print $sum}'
    and
    perl -le '$sum+=$_ while <>; print $sum'
    don't slurp either. <> is an iterator (in scalar context).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found