in reply to Re: --- adding a column of integers
in thread adding a column of integers
awk '{s += $0} END {print s}'
Also
or even (with gnu sed)(echo 0;sed s,$,+, inputfile;echo p)|dc
but the point of the OP was to improve his Perl skills.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
Update 2007 dec 6: see also Re: Golf: Adding up array elements
|
---|
In Section
Seekers of Perl Wisdom