Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to keep running total?

by jethro (Monsignor)
on Apr 27, 2013 at 14:50 UTC ( #1030976=note: print w/ replies, xml ) Need Help??


in reply to How to keep running total?

First of all I don't see a reason to use a state machine. You just have lots of lines and a special action to do when the date changes. So I would throw out the variable $state completely

Also there is no reason for the counting to be done in an else-clause. You want to count every line.

To avoid printing the first time (when you haven't counted anything yet) just check for the empty string in date

If you want to try it for yourself don't reveal the spoiler, otherwise here is how the loop could be done (untested):


Comment on Re: How to keep running total?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-11-25 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls