不能使用未定义的值作为 ARRAY 引用

Can't use an undefined value as an ARRAY reference

我有一个用 perl 编写的简单脚本,当我尝试 运行 时,我总是收到这个特定的错误。该脚本用于生成一些数字,用于检查整数到浮点数。这是我得到的特定错误。

Can't use an undefined value as an ARRAY reference at /tools/oss/packages/i86pc-5.10/perl/5.8.8-32/lib/5.8.8/Math/BigInt/Calc.pm line 1180

从错误消息中我无法找出我的代码哪里出错了。顺便说一下,我需要使用 64 位数字。我该如何调试这个问题?

这是代码示例

use bignum;
use warnings;
use strict;

open(VCVT, ">CvtIntToFp") or die "couldn't open file to write:$!";

my $number;
my $sgn;

# left with 31 bits excluding the sign
# 23 bits of significand needed, all the result
# will be exact except where leading bit ignoring singn is >23
# take its 2's complement to get the negative number  and put it
# into the register
# 32 bit number 1 bit sign 31 left any number with leading 1 @position >23 (counting from 0) will be inexact when in floating point
# 30-24 bit positons can have a leading ones at at any position and result is an inexact

my $twoPwr32 = 0x100000000; #2**32

my @num=();

for(my $i=0; $i<100; $i++)
{
    $sgn = (rand()%2);
    my $tempLead = (rand()%7); # there are 7 bits from 24 to 30
    $number=$tempLead << 24;
    if($sgn)
    {$number = ($twoPwr32- $number +1) & 0xffffffff;
    }
    $number = sprintf("%x", $number);
    push(@num, $number);
}
my $item=0;
foreach $item (@num)
{
    print "$item\n";
    print VCVT "$item\n";
}

尝试使用 use diagnostics 以获得更好的错误消息并阅读 perldoc bignum。那里给出了错误和解释,即 bignum 的使用在内部将数字转换为 bignum 和 returns 引用。因为我有 perl 5.14 文档,所以我有 perl 5.20 文档的 link,我认为这个错误仍然存​​在。参考http://perldoc.perl.org/bignum.html

更新:

Hexadecimal number > 0xffffffff non-portable at throw_stack.pl line 19 (#1)
    (W portable) The hexadecimal number you specified is larger than 2**32-1
    (4294967295) and therefore non-portable between systems.  See
    perlport for more on portability concerns.

另请参阅this问题,了解 Perl 中 64 位算法的用法。