in reply to processing timelog
you might want to try this:
Executing it gives the following:use strict; use warnings; my ($tot1, $tot2); while (<DATA>) { chomp; s/\s+$//g; next unless /TP Service Request$/ or /P5 Move request$/; my ($datetime, $ms, $inid, $message) = split /,/, $_; my $date = substr $datetime,11; my ($hours, $min, $sec) = map { $_ * 1000} split /:/, $date; $hours *= 60 * 60; $min *= 60; my $total_time = $hours + $min + $sec + $ms; $tot1 = $total_time if $message eq "TP Service Request"; $tot2 = $total_time if $message eq "P5 Move request"; next unless defined $tot2; print "Duration is: ", $tot2 - $tot1, " ms.\n"; last; } __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 ... (rest of data omitted from this post for brevity)
There are some issues left. For example, this does not work correctly if the date changes between the two dates/times. Please note that I have also tried to make the code more "DRY" (Don't Repeat Yourself).$ perl log_files.pl Duration is: 46426 ms.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: processing timelog
by sandy105 (Scribe) on Aug 24, 2014 at 11:29 UTC | |
by Anonymous Monk on Aug 24, 2014 at 11:45 UTC | |
by sandy105 (Scribe) on Aug 25, 2014 at 08:10 UTC | |
by poj (Abbot) on Aug 24, 2014 at 20:41 UTC | |
|
Re^2: processing timelog
by sandy105 (Scribe) on Aug 25, 2014 at 08:11 UTC |