Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Summing numbers -- oneliner

by Discipulus (Canon)
on Nov 20, 2018 at 10:39 UTC ( [id://1226056]=note: print w/replies, xml ) Need Help??


in reply to Summing numbers

Hello catfish1116

you already got good answers: a question: why you use state ? I personally never used it and I wonder if is the right thing to do in your example.

Anyway I offer you a oneliner (bewere of windows doublequotes!) use CTRL-Z on an empty line to end STDIN input. use CTRL-D on linux:

perl -e "$sum += $_ while $_ = <STDIN> and chomp; print qq(total: $sum +\n)" 1 2 3 4 ^Z total: 10

You also find useful the evil form of eval like in perl -e "push @sum,$_ while $_ = <STDIN> and chomp; print qq(total: ),(eval join '+',@sum),qq(\n)"

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found