I have timestamp log that looks like this:
2000-11-09 12:19:08.000 2000-11-09 14:09:17.000 2000-11-09 15:23:55.000 2000-11-09 13:12:23.000
I want to get the difference between the earliest and the latest timestamp
This is what I currently have, but I suspect that it can be made MUCH more efficient
What do you think?
use Time::Local; # Array read from log; contains timestamps in any order: my @TIMES = <LOG>; # Sort array to get the smallest timestamp first and the largest t +imestamp last: sort(@TIMES); # re-arrange order to use in timelocal function: my ($year1,$mon1,$mday1,$hours1,$min1,$sec1) = ( $TIMES[0] = +~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+).000/ ); my ($year2,$mon2,$mday2,$hours2,$min2,$sec2) = ( $TIMES[$#TIMES] = +~ /(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+).000/ ); # get timestamp in seconds since beggining of time (in unix world) +: $START_LAUNCH = timelocal($sec1,$min1,$hours1,$mday1,$mon1,$year1) +; $END_LAUNCH = timelocal($sec2,$min2,$hours2,$mday2,$mon2,$year2) +; # Get difference & Round off to two decimals: $TimeInMinutes = sprintf("%.2f",(($END_LAUNCH - $START_LAUNCH)/60) +); return $TimeInMinutes;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |