use 5.10.1;
use strict;
use Time::Local;
use Time::localtime;
use IO::File;
my $ti = localtime;
my $tf;
my ($logFile, $logFileH);
my $basePath = "c:\\las\\dump";
my $processName = "dummy process";
my $startState = "enabled";
my $deaths = 4;
my $diff;
my $processNameOut;
my $startStateOut;
my $deathsOut;
my $deathFile = "$basePath\\itrsDeaths.dat";
my $deathFileH = new IO::File(">$deathFile") or logit("Can't open fi
+le: $deathFile for output.\n");
printf $deathFileH ("%-35s%-9s %-5d %s\n", $processName, $startState
+, $deaths,$ti);
if ( -f "$deathFile") {
open(INIFILE,'<',"$deathFile") or logit( "Could not open death fil
+e $deathFile: $!");
my @records = <INIFILE>;
foreach my $record (@records) {
my ($processNameOut, $startStateOut, $deathsOut, $ti) = $record
+=~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?/;
}
close INIFILE;
}
else {
open(INIFILE,'>',"$deathFile") or logit( "Could not create death f
+ile $deathFile: $!");
close INIFILE;
}
sleep(2);
$tf = localtime;
$diff = getTimeDifferenceInSeconds($ti,$tf);
say "The time difference in seconds is $diff";
sub getTimeDifferenceInSeconds {
my ($t1,$t2) = @_;
my $sec1 = $t1->sec;
my $sec2 = $t2->sec;
my $min1 = $t1->min;
my $min2 = $t2->min;
my $hour1 = $t1->hour;
my $hour2 = $t2->hour;
my $mday1 = $t1->mday;
my $mday2 = $t2->mday;
my $month1 = $t1->mon;
my $month2 = $t2->mon;
my $year1 = $t1->year;
my $year2 = $t2->year;
my $diff;
my $es1 = timegm($sec1,$min1,$hour1,$mday1,$month1-1,$year1);
my $es2 = timegm($sec2,$min2,$hour2,$mday2,$month2-1,$year2);
$diff = $es2-$es1;
return $diff;
}
sub logit {
print @_;
# print $logFileH @_ if ($ENV{ENABLE_ITRS_LOGGING});
}
|