[lug] Perl and large numbers on (K)ubuntu

David L. Anselmi anselmi at anselmi.us
Mon Sep 26 19:30:59 MDT 2011

Gary Hodges wrote:
> #!/usr/bin/perl
> use Date::Manip;
> my $secs = 2147483647;  # Increment by one to see the error
> my $time =&DateCalc("Jan 1, 1900  00:00:00","+ $secs");
> print "$secs $time\n";  # $time is in yyyymmddhh:mn:ss format
> # My output (second line is w/secs incremented by one):
> # 2147483647 1968012003:14:07
> # 2147483648 1831121320:45:56

So Date::Manip is treating your unsigned, 32 bit int as signed.

What will happen if you convert the date to seconds, add your seconds, and then convert back to a date?

Also, "use bigint" might help.  Or it might not:

> Here is the output of "perl -V".

>       use64bitint=undef, use64bitall=undef, uselongdouble=undef

My use64bitint=defined and your code works fine for me (on AMD64 and x86).

You could also try Date::Calc and see how it behaves.


More information about the LUG mailing list