-----Original Message----- >From: timbo <[EMAIL PROTECTED]> >Sent: Aug 8, 2007 1:47 AM >To: beginners@perl.org >Subject: Timelocal's input parameters > >Is it possible to pass timelocal a parameter that's already the exact >scalar output of localtime's format "Mon Jan 10 04:30:30 2007"? > >I know the perlfunc documentations for timelocal indicates that >arguments are in the form of ... > >timelocal($seconds, $minutes, $hours, $day, $month, $year) > >but I have a logfile with the above time format & want to know if >there's an easier way of reading that entry & pass it to timelocal so >as to get the epoch time. >So far I can only think of using regex as the best solution but any >smarter solution will be happily appreciated. >
This is the answer from Chris Charley,who helped the list with the same question,and I remembered his answer below: #!/usr/bin/perl use strict; use warnings; use Time::Local; my %month; @month{ qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/ } = 0..11; my $date = "Thu Mar 9 23:04:03 2006"; my (undef, $month, $day, $h, $m, $s, $year) = split /\W+/, $date; my $time = timelocal($s,$m,$h,$day,$month{$month},$year); print $time,$/; print scalar localtime $time; (Prints) 1141963443 Thu Mar 9 23:04:03 2006 -- Jeff Pang <[EMAIL PROTECTED]> http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/