P
pj_sammie
I am trying to convert a localtime generated in a log file, to unix
time for storage in a db. In the script below, it properly converts if
I generate a localtime within the script. But, it won't properly
convert when using a sample line from the log file. I am stumped...
Thanks for any help.
CODE
---------
use Time::Local;
# Doesn't convert propely
$thetimel = "Tue Sep 28 17:12:13 2004";
print "$thetimel\n";
&convert_time;
# Does convert properly
$currenttime = time();
$thetimel = localtime($currenttime);
print "$thetimel\n";
&convert_time;
sub convert_time {
if ($thetimel =~ /\w+\W+(\w+)\W+(\d+)\W+(\d+)\d+)\d+)\W+(\d+)/)
{
$mon = $1;
$mday = $2;
$hours = $3;
$min = $4;
$sec = $5;
$year = $6;
}
$thetimes = timelocal($sec, $min, $hours, $mday, $mon, $year);
print "$sec, $min, $hours, $mday, $mon, $year\n";
print "$thetimel => $thetimes\n";
print "$thetimes => " . localtime($thetimes) . "\n\n";
}
time for storage in a db. In the script below, it properly converts if
I generate a localtime within the script. But, it won't properly
convert when using a sample line from the log file. I am stumped...
Thanks for any help.
CODE
---------
use Time::Local;
# Doesn't convert propely
$thetimel = "Tue Sep 28 17:12:13 2004";
print "$thetimel\n";
&convert_time;
# Does convert properly
$currenttime = time();
$thetimel = localtime($currenttime);
print "$thetimel\n";
&convert_time;
sub convert_time {
if ($thetimel =~ /\w+\W+(\w+)\W+(\d+)\W+(\d+)\d+)\d+)\W+(\d+)/)
{
$mon = $1;
$mday = $2;
$hours = $3;
$min = $4;
$sec = $5;
$year = $6;
}
$thetimes = timelocal($sec, $min, $hours, $mday, $mon, $year);
print "$sec, $min, $hours, $mday, $mon, $year\n";
print "$thetimel => $thetimes\n";
print "$thetimes => " . localtime($thetimes) . "\n\n";
}