in reply to processing timelog

I suggest you first parse your timelog and put the data into a data structure that you can then more easily traverse.
use Modern::Perl qw/2014/; use DateTime; use DateTime::Format::Flexible; use DateTime::Duration; my %data; while (<DATA>) { chomp; my ( $datetime, $msecs, $id, $description ) = split /,/; $msecs *=1000000; $datetime .= ":$msecs"; my $dt = DateTime::Format::Flexible->parse_datetime($datetime); $data{$id}->{$description} = $dt; } for my $id ( keys %data ) { print "Results for $id: "; if ( exists $data{$id}{'P5 Move request'} and exists $data{$id}{'TP Service Request'} ) { my $duration = $data{$id}{'P5 Move request'} ->subtract_datetime_absolute( $data{$id}{'TP Service Request +'} ); say "$data{$id}{'P5 Move request'} -> $data{$id}{'TP Service Request'} = " +, $duration->seconds + $duration->nanoseconds/1000000000, ' se +conds'; } else { say 'Missing data'; } } __DATA__ 2014-05-29 10:22:21,880,165ab6a8-e736-11e3-8748-8d365226be24,TP Servic +e Request 2014-05-29 10:22:21,962,165ab6a8-e736-11e3-8748-8d365226be24,ProcessNa +me: TC 2014-05-29 10:22:21,965,165ab6a8-e736-11e3-8748-8d365226be24,P5 Starte +d (...) 2014-05-29 07:14:04,048,1770ebca-e722-11e3-b793-c6903cc19f13,P5 Move r +equest
Output:
Results for 1770ebca-e722-11e3-b793-c6903cc19f13: Missing data Results for 165ab6a8-e736-11e3-8748-8d365226be24: 2014-05-29T10:23:08 +-> 2014-05-29T10:22:21 = 46.426 seconds
As you see, calculating the time between a "P5 Move request" and "TP Service Request" gets really easy: a few look-ups in the data structure is all that is needed. As the datetime is a DateTime-object, calculating the difference (i.e. duration) between two datetimes requires no complicated calculations.

Two more comments:

  1. If for the same ID you can have multiple processes with the same name, this data-structure is too simple as a later process will overwrite the data of a previous one.
  2. Always use a DateTime (or similar) object to represent a datetime. Time and date calculations are fraught with exceptions and special rules. Not all hours are 60 minutes and not all minutes are 60 seconds. The DateTime module takes care of all of that.

Update: Amended code to take into account the millisecond field in the timelog.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics