
alferic
Novice
Apr 14, 2014, 1:40 AM
Post #1 of 7
(4086 views)
|
compare timegm
|
Can't Post
|
|
hello Guru's I need your help again. I wanted to get the earliest time from the "Inspection Start" column and the get the latest time from the "Inspection Stop" column. The issue is my script does not seem to correctly pick up the earliest time. Or is it possible to compare timegm format using the script below My data: Inspection Start Inspection Stop E4855 WI_LEFT01 3/12/2014_5:00:09_AM 3/12/2014_5:02:08_AM 1m_59s 9334 8195 8135 59 1 60 99.27 H0096 WI_LEFT01 3/12/2014_5:22:58_AM 3/12/2014_5:24:55_AM 1m_57s 9334 8197 8138 58 1 59 99.28 L0998 WI_LEFT01 3/12/2014_5:29:13_AM 3/12/2014_5:31:09_AM 1m_56s 9334 8163 8088 73 2 75 99.08 P0113 WI_LEFT01 3/12/2014_5:15:37_AM 3/12/2014_5:17:39_AM 2m_2s 9334 8008 7927 80 1 81 98.99 P0149 WI_LEFT01 3/12/2014_5:12:36_AM 3/12/2014_5:14:31_AM 1m_55s 9334 8195 8125 68 2 70 99.15 T2765 WI_LEFT01 3/12/2014_5:25:59_AM 3/12/2014_5:28:00_AM 2m_1s 9334 7810 7732 77 1 78 99.00 T5518 WI_LEFT01 3/12/2014_5:04:37_AM 3/12/2014_5:06:37_AM 2m_0s 9334 8182 8107 73 2 75 99.08 my code: #!/usr/bin/perl use Time::timegm; my $line = ""; my $ins_start_time =""; my $ins_end_time =""; my $tst_start_time =""; my $tst_start_time =""; open FH, "<file.txt" or die "could not open file, $!"; while($line=<FH>) { chomp($line); $line =~ s/\cM//g; my @dummy = split /\s/, $line; #print "$line\n"; if ($dummy[0] =~ /^[A-Z]\d{0,4}$/i) { ($dump, $dump, $st_dump, $et_dump, @dump) = @dummy; ($mm, $dd, $yy, $hh, $min, $sec, $dump) = split /[\/\_\:]+/, $st_dump; $ins_start_time = timegm($sec, $min, $hh, $dd, $mm-1, $yy); print "$ins_start_time\t"; if ($tst_start_time <= $ins_start_time) { $tst_start_time = $ins_start_time; } ($mm, $dd, $yy, $hh, $min, $sec, $dump) = split /[\/\_\:]+/, $et_dump; $ins_end_time = timegm($sec, $min, $hh, $dd, $mm-1, $yy); print "$ins_end_time\n"; if ($ins_end_time >= $tst_end_time) { $tst_end_time = $ins_end_time; } } } close FH; print "Start Time =$tst_start_time\n"; print "Start Time =$tst_end_time\n"; OUTPUT: 1394600409 1394600528 1394601778 1394601895 1394602153 1394602269 1394601337 1394601459 1394601156 1394601271 1394601959 1394602080 1394600677 1394600797 Start Time =1394602153 ---->incorrect Start Time =1394602269 REQUIRED OUTPUT: 1394600409 1394600528 1394601778 1394601895 1394602153 1394602269 1394601337 1394601459 1394601156 1394601271 1394601959 1394602080 1394600677 1394600797 Start Time =1394600409 Start Time =1394602269
|