in reply to Calculating time between two events in a log.

G'day perlguyjoe,

Welcome to the monastery.

Assuming the ,NNN after each HH:MM:SS represents NNN milliseconds, you can use Time::Piece to calculate the time difference like this:

$ perl -Mstrict -Mwarnings -le ' use Time::Piece; my $tp_format = "%Y-%m-%d %H:%M:%S"; sub get_ms { my ($ts, $ms) = split /,/ => shift; Time::Piece->strptime($ts, $tp_format)->epoch * 1000 + $ms; } my $invoke = "2013-08-09 13:00:23,784"; my $success = "2013-08-09 13:00:23,791"; print "Time diff: ", get_ms($success) - get_ms($invoke), "ms"; ' Time diff: 7ms

Please do the following prior to posting again:

-- Ken

Replies are listed 'Best First'.
Re^2: Calculating time between two events in a log.
by perlguyjoe (Novice) on Aug 13, 2013 at 17:09 UTC
    Thanks Ken, and sorry to everyone about my bad post format I have cleaned it up. Your example would work great but I am limited in what modules I can use and Timepiece is not one of them. I should have clarified that. Additionally, the time could be measured in milliseconds or seconds. I am trying to report on the delay which sometime creeps upwards of 30 seconds or more. Any other ideas are welcome, and thanks in advance!
      "Your example would work great but I am limited in what modules I can use and Timepiece is not one of them. I should have clarified that."

      You still can clarify that with an update to your OP explaining the constraints you're working under. I have no idea whether:

      • this is schoolwork and you need to demonstrate that you understand date/time manipulation
      • you didn't know that Time::Piece (builtin) has been included with Perl since version 5.10.0
      • you have a version of Perl prior to 5.10.0 and have some restriction on using CPAN
      • you were unaware that you could install Time::Piece from CPAN
      • there is some other limitation involved

      For future reference, please consider including this type of information when you first post. While we're happy to help, we don't really like hearing: "Your solution is useless to me because of something I'm not telling you about.".

      -- Ken