in reply to Summing numbers
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*
|
---|