choroba has asked for the wisdom of the Perl Monks concerning the following question:

I am debugging an old version of Date::Manip (5.42) in an ancient version of Perl (5.8.3). Can anyone explain what's going on? This is the command being run (do not ask me why):
perl -d -l -MDate::Manip -e 'Date_Init("Internal=1"); print Date_NextW +orkDay(ParseDate("today"), ParseDate("today"))'

In a recent Perl, it loops for a long time, and eventually returns with

ERROR: Invalid year (10000)

This is the important part of the debugging session:

DB<2> l 3558: while ($off>0) { 3559: while (1) { 3560: $date=&DateCalc_DateDelta($date,"+0:0:0:1:0:0:0",\$err,0 +); 3561: last if (&Date_IsWorkDay($date,$time)); 3562 } 3563: $off--; 3564 } 3565 3566: return $date; 3567 } DB<2> c 3558 Date::Manip::Date_NextWorkDay(/home/legacy/perl/lib/site_perl/5.8.3/Da +te/Manip.pm:3558): 3558: while ($off>0) { DB<3> x $off 0 20131016053748 DB<4> print "Greater" if $off>0; Greater DB<5> s Date::Manip::Date_NextWorkDay(/home/legacy/perl/lib/site_perl/5.8.3/Da +te/Manip.pm:3566): 3566: return $date; DB<5> use Devel::Peek; print Dump $off; SV = PVMG(0x87f2fb0) at 0x84b42e8 REFCNT = 2 FLAGS = (PADBUSY,PADMY,NOK,POK,pIOK,pNOK,pPOK) UV = 4294967295 NV = 20131016053748 PV = 0x87f2eb8 "20131016053748"\0 CUR = 14 LEN = 15

The question is: does anyone remember a bug in Perl similar to this? It looks like $off was erroneously treated as negative in the underlying C, but I am not sure.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re: Loop Not Entered (integer.pm)
by tye (Sage) on Oct 16, 2013 at 14:03 UTC
      Thanks a lot, that was it. integer does not propagate to the debugger's scope. Also, some of our machines have different sizes of integers, so the same code works differently on different machines.
      use integer; $off = 201310170300350000000; print $off if $off > 0;
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Note that I strongly discourage the use of integer.pm. The first paragraph of the documentation contains this whopper: "but on those without floating point hardware, it can make a big difference in performance". Good luck finding a computer without floating point acceleration that is still running. But even if you do, the slow down from doing floating point calculations is quite unlikely to be noticeable much less "a big difference" when talking about a Perl script.

        Even worse is the other whopper from the first paragraph: "On many machines, this doesn't matter a great deal for most computations". Actually, it very often matters a lot for lots of computations not just because it prevents fractional values from being preserved but also because it very often greatly reduces the size of integer values that can be used.

        int, however, allows faithful and accurate use of integer arithmetic to at least 52 bits on just about every platform I've seen Perl run on. Just use that instead.

        - tye        

Re: Loop Not Entered ( Date::Manip 5.42)
by Anonymous Monk on Oct 16, 2013 at 13:41 UTC