Perl Gem, Simple Math Error


Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/parser/Preprocessor_DOM.php on line 754

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
From Bilbo

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
Jump to:
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
navigation

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
,
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
search

2006-08-30

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).
#!/usr/bin/perl
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.