Ow, Calling an external command works too. There is always more than 1 way of doing something in perl.
Just that it will not be portable across different Unix platforms. The 'date' command is not the same across different Unix. Calling external command is also slow. Depends on how often you need to call it, it may or may not impact the performance of the whole program. For example, If you are processing 1 million lines of source data, it could be substantial. But if you just need to process 100 lines of source, no difference. timelocal() is the reverse of localtime(). Given a list of ($sec,$min,$hour,$mday,$mon,$year), it returns the time. Anyway, welcome to the world of Perl Programming. Enjoy! Regards Soong On Mon, 2007-08-13 at 17:19 +0800, [EMAIL PROTECTED] wrote: > > -------- Original Message -------- > Subject: Re: [Fwd: [Slugnet] Help with Perl Datetime + Epoch] > Date: Mon, 13 Aug 2007 16:09:50 +0800 > From: Ow Mun Heng <[EMAIL PROTECTED]> > To: lena <[EMAIL PROTECTED]> > CC: [EMAIL PROTECTED], [email protected] > References: <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > > > > On Mon, 2007-08-13 at 15:44 +0800, lena wrote: > > Ow, > > > > Although the previous program works. There is a typo, "$d should be > > $date". corrected version below: > > > > #!/usr/bin/perl > > > > require "timelocal.pl"; > > > > sub rdxtime > > { > > my ( $date ) = @_ ; > > my @t = split(/[-:\s]/,$date); > > $t[0] -= 1900; $t[1] -= 1; # check manpage of localtime > > @t = reverse(@t); > > return timelocal(@t); > > } > > > > $d = "2007-08-13 14:39:48"; > > > > print rdxtime ($d); > > > > > Thanks Man.. BTW, what is timelocal.pl? > > Anyway.. I finally relented and just subcumed to using local bash and > backticks. > > this 1 liner got me what I wanted. (kinda surprising that a solution > using perl was that complicated) > > $epoch_base_datetime=`date -d \"$start_date\" +%s`; > > start_date -> 2007-07-31 12:00:00 > epoch_base_datetime -> 1185854400 > > > > _______________________________________________ Slugnet mailing list [email protected] http://www.lugs.org.sg/mailman/listinfo/slugnet
