i think the algorithm you want to use looks like this (in pseudo-code):

foreach $line (@lines) { ($time, $id, $open) = parse($line); next until $code eq 'open'; $open = $time; until ($code eq 'hold') { $line = shift(@lines); ($time, $id, $code) = parse($line); $total += $time-$open; }
now, the real problem comes in if you have multiple IDs mixed together. then you have to get much more intericate, because you need to keep track of whether that ID is open or not. for that, you might do something like this:
while (@lines) { $line = shift(@lines); ($time, $id, $code) = parse($line); $hash{$id}{want} ||= 'open'; next unless ($hash{$id}{want} eq $code); if ($code eq 'open') { $hash{$id}{open} = $time; $hash{$id}{want} = 'hold'; } else { $hash{$id}{total} += $time - $hash{$id}{open}; $hash{$id}{want} = 'open'; delete $hash{$id}{open}; } }
what i'm doing in this latter is keeping track, for each ID, of whether i am currently open (want = 'hold') or currently on hold (want = 'open'). if i am on hold, and find an open, i start keeping track. if i am currently open and go on hold, i subtract the new time minus when i opened, and i was open for that long, so i add it to my total.

does that make sense? it might not be the most efficient way to do it, but it seems to me it'd get the job done. Note that this is just the idea; you'll ahev to make the variables match yours, and write your own parse(), etc. but i think you were just looking for the idea.

hope that helps

.

In reply to Re: Funky date question. by Vynce
in thread Funky date question. by Mark 1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.