penguin2020
Programmer
I have 2 files one contains time string values in the following format 09:00.000 and another file that has time string valuesin the same format
I am interested in calculating the millisecond time difference between each of the two files
e.g the time in the first row of file a minus the tim in the first row of file b and so on until the end of each file. Both files contain the same number of time entries.
I thought that I would
-read each file into a separate array
- loop through via foreach and subtract array_a[0] from array_b[0] and so on.
Problem is I don't know how to do it
Heres my code
{CODE}
#!/usr/bin/perl
$ltimefile="linetime.txt";
$stimefile="sendtime.txt";
open(TZ1, $stimefile);
@stimefinal=<TZ1>;
close(TZ1);
open(TZ2, $ltimefile);
@limefinal=<TZ2>;
close(TZ2);
foreach(@ltimefile, @stimefile){
$ltimefile - $stimefile
my @components = split /[:\.]/, shift;
return (($components[0] * 60 + $components[1]) * 60 + $components[
+2]) * 1000 + $components[3];
}
}
{CODE}
#timestamps in both files look like this
7:18:00.416
17:51:41.580
07:18:10.983
17:51:41.773
07:18:11.866
17:51:41.799
07:18:12.079
17:51:41.805
07:18:13.642
17:51:41.853
07:18:13.642
17:51:41.853
07:18:13.647
17:51:41.853
07:18:13.658
17:51:41.854
07:18:13.667
17:51:41.855
07:18:14.731
17:51:41.890
07:18:14.738
17:51:41.890
07:18:14.877
17:51:41.896
07:18:14.877
#
#
Please help!
I am interested in calculating the millisecond time difference between each of the two files
e.g the time in the first row of file a minus the tim in the first row of file b and so on until the end of each file. Both files contain the same number of time entries.
I thought that I would
-read each file into a separate array
- loop through via foreach and subtract array_a[0] from array_b[0] and so on.
Problem is I don't know how to do it
Heres my code
{CODE}
#!/usr/bin/perl
$ltimefile="linetime.txt";
$stimefile="sendtime.txt";
open(TZ1, $stimefile);
@stimefinal=<TZ1>;
close(TZ1);
open(TZ2, $ltimefile);
@limefinal=<TZ2>;
close(TZ2);
foreach(@ltimefile, @stimefile){
$ltimefile - $stimefile
my @components = split /[:\.]/, shift;
return (($components[0] * 60 + $components[1]) * 60 + $components[
+2]) * 1000 + $components[3];
}
}
{CODE}
#timestamps in both files look like this
7:18:00.416
17:51:41.580
07:18:10.983
17:51:41.773
07:18:11.866
17:51:41.799
07:18:12.079
17:51:41.805
07:18:13.642
17:51:41.853
07:18:13.642
17:51:41.853
07:18:13.647
17:51:41.853
07:18:13.658
17:51:41.854
07:18:13.667
17:51:41.855
07:18:14.731
17:51:41.890
07:18:14.738
17:51:41.890
07:18:14.877
17:51:41.896
07:18:14.877
#
#
Please help!