Welcome to WebmasterWorld Guest from 54.159.190.106

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl date limits -and- how to get milliseconds?

Two questions, perl date and how to get time in milliseconds?

   
11:47 pm on Dec 2, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi webmasters, instead of opening two threads, two questions here.

1. Should I worry on the limits of date (year) in Perl? I know Perl has its own y2k sort of limit on 2039 I think. I read about it and it was mentioned that we should not worry if the admins update the core whatever from 32 bits to 64 and perhaps newer versions of perl would eliminate this problem. Any ideas?

2. How do you get milliseconds in Perl? I can only get time down to seconds. I'm working on my latest CMS putting some new features I find very useful, but for several reasons including measuring how much time it takes to generate some simple and complex pages I would like to include on the page "this page was generated in XX milliseconds... or seconds". I like to go simple and fast but some procedures require tweaking.

Thanks
1:44 am on Dec 3, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Got the ms:

sub ms{
($s, $usec) = gettimeofday();
$tsec=int($usec/1000);
$seg="$s.$tsec";
return $seg;
}


From there is only a matter of getting the ms at the beginning of the operation and then again at the end, then just do the math between the two and there you go.

As for the date (years) limit in perl I'm still wondering what's the best metod or just sticking to localtime.
9:00 am on Dec 3, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



or you could use Benchmark.pm:
http://search.cpan.org/~jesse/perl-5.12.2/lib/Benchmark.pm [search.cpan.org]

this should address your first question.
Does Perl have a Year 2000 or 2038 problem? Is Perl Y2K compliant?:
http://perldoc.perl.org/perlfaq4.html#Does-Perl-have-a-Year-2000-or-2038-problem%3f-Is-Perl-Y2K-compliant%3f [perldoc.perl.org]
8:22 pm on Dec 7, 2010 (gmt 0)

5+ Year Member



Perl 5.12 has 64-bit time on 32-bit systems too. If you have older Perl, you can use DateTime CPAN module.

For milliseconds use Time::HiRes.
12:32 am on Dec 8, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



re: Time::HiRes module & Benchmark.pm:
http://search.cpan.org/~jesse/perl-5.12.2/lib/Benchmark.pm#:hireswallclock [search.cpan.org]
4:29 am on Dec 13, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Glad to know Perl 5.12 has 64 bit time.

Thanks for the help, now i have more clear what to do.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month