Perl Gem, Simple Math Error

From Bilbo
Jump to: navigation, search


This one is a doozy. I have no idea wtf is going on here. I do know a couple things:

  • Without "use bignum;" the code works.
  • perl -v says: This is perl, v5.8.8 built for i386-freebsd-64int
  • The surrounding foreach loop does make a difference. Substituting a simple assignment does not reveal the bug.
  • I want my 3 wasted hours of my life back, dammit (plus my rant time here).
use strict;
use warnings;
use bignum;

foreach my $char ('A') {
        print "IN: $char\n";

        $char = ord($char) - ord('A') + 10;
# The line above does NOT work, but the two lines below DO.
#       my $tmp = ord($char) - ord('A') + 10;
#       $char = $tmp;

        print STDERR "OUT: $char  <-- should not be 'A'!\n";

This came up while I was working on Pit, when I added "use bignum;". This came from my code to convert non-decimal integers to decimal. It's stripped down as slim as I could make it while still revealing the error.