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.