in reply to Re: Re: Funky date question.
in thread Funky date question.
Okay, I'll give this a shot; it appears you're looking for the logic, and not the code (which is good, because I'm not that good at Perl yet :). Anyway, here's my attempt at pseudocoding your problem:
my ($starttime, $isopen, $totaltime) = (0, 0, 0); while (<TIMELOG>) { if (/open$/) { next if $isopen; $isopen = 1; $starttime = getseconds($_); } elsif (/hold$/ || /closed$/) { next unless $isopen; $isopen = 0; $totaltime += getseconds($_) - $starttime; } }
Well, that came out a bit closer to code than I had intended... oh well. I hope that helps.
Update: (1000 CDT 09 Jun) It occurred to me a bit more explanation might be in order. Basically, as I understand it, the key to your problem is to keep track of the first time you noticed the ID was in an open state, and only perform the addition to $totaltime when the ID moves out of the open state (and presumably, into one of the closed or hold states).
Also, having watched a bit of the CB discussion on this topic, I noticed that you want to run this in realtime. If that's the case, you may want to generate a fake log entry to be processed at the end with the current time and a non-open state to force the calculation of the open time. This would change the code to be more like this:
@lines = <TIMELOG>; push @lines, makefake(time(), "closed"); for (@lines) { # Same loop body }
Update #2: Edited code and above comments on real time about current state.
I know it might not be the optimal method to do it, but it seems as if it should get the job done (if I understand the job to be done correctly). Try it out - if it doesn't work, let me know. If it does, let me know then, too - I never know when I might need this bit of code. :)
CheeseLord
|
|---|