Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: --- adding a column of integers

by ambrus (Abbot)
on Sep 03, 2004 at 20:35 UTC ( #388399=note: print w/replies, xml ) Need Help??

in reply to Re: --- adding a column of integers
in thread adding a column of integers

awk '{s += $0} END {print s}'


(echo 0;sed s,$,+, inputfile;echo p)|dc
or even (with gnu sed)
sed ' G s/^ *\([0-9]*\) *\n\([0-9]*\)$/0\1pm0\2nb0/;td;d; :d;s/n\(\(b\).*0\|\)[^0]*$/nb98765432109876543210a0123456789\2/; s/\(.\)\(p.*\)\(.\)\(n.*\1\).*a.*\3/\2\4\3/; s/^0*\(.*\)p\(.*m\)0*\(.*\)\(.\).\{11\}$/0\1p\4\20\3/; /m0*n.*0/!bd; s/^\(.*\)p\(.*\)m.*/\1\2/;s/^0*//; h;$!d ' inputfile
but the point of the OP was to improve his Perl skills.

Update 2007 dec 6: see also Re: Golf: Adding up array elements

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388399]
[Corion]: Ouch. I just learned something about Chrome - the "version numbers" are not really feature numbers... Chrome 62 still gets new features even though Chrome 64 is out and Chrome 65 is the dev version
[erix]: why ouch? Something to be said for that ,surely?
LanX is a dev version
[marto]: That reminds me, I made some notes somewhere with regard W::M::C, I'll get round to a PR when I've time to flesh it out
[Corion]: erix: But that makes for fun bug hunting. "What version of Chrome are you running?" "v62". "I also run v62 and it works on my machine". :-(
[Corion]: marto: Great, looking forward to the PR!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-12-12 20:13 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.