in reply to Funky date question.

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

.