Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 试图修改不可创建的数组值,下标-2147483648_Perl_Integer Overflow - Fatal编程技术网

Perl 试图修改不可创建的数组值,下标-2147483648

Perl 试图修改不可创建的数组值,下标-2147483648,perl,integer-overflow,Perl,Integer Overflow,我对Perl还不太熟悉,所以请耐心等待 我得到这个错误: 试图修改不可创建的数组值,下标 -2147483648在 根据该代码: while (@data) { my $datum = shift @data; #print "adding $datum at $an\n"; $mem[$an] = $datum; $an++; } mem在此声明: @mem = (); 现在,当地址开始超过2G限制(0x8000000)时,问题出现了。因此,这看起来

我对Perl还不太熟悉,所以请耐心等待

我得到这个错误:

试图修改不可创建的数组值,下标 -2147483648在

根据该代码:

while (@data) {
    my $datum = shift @data;
    #print "adding $datum at $an\n";
    $mem[$an] = $datum;
    $an++;
    }
mem在此声明:

@mem = ();
现在,当地址开始超过2G限制(0x8000000)时,问题出现了。因此,这看起来与整数溢出有关,导致数字被解释为负数。如何告诉Perl我使用的是无符号32位整数


谢谢

尝试使用
push
功能

    while (@data) {
        my $datum = shift @data;
        #print "adding $datum at $an\n";
        push (@mem, $datum); ## this adds the new element at the end of the @mem array.
   }
要了解更多有关
推送的信息,请学习

如果要使用
哈希
,请使用以下代码:

my %mem = ();
while (@data) {
            my $datum = shift @data;
            #print "adding $datum at $an\n";
            $mem{$an} = $datum;
            $an++; ## Increment the key so as to avoid overwriting of the value.
}

尝试使用
push
功能

    while (@data) {
        my $datum = shift @data;
        #print "adding $datum at $an\n";
        push (@mem, $datum); ## this adds the new element at the end of the @mem array.
   }
要了解更多有关
推送的信息,请学习

如果要使用
哈希
,请使用以下代码:

my %mem = ();
while (@data) {
            my $datum = shift @data;
            #print "adding $datum at $an\n";
            $mem{$an} = $datum;
            $an++; ## Increment the key so as to avoid overwriting of the value.
}
使用散列(关联数组),而不是数组。Perl数组的设计并不是为了稀疏地使用

my %mem;
...
   $mem{$an} = $datum;
使用散列(关联数组),而不是数组。Perl数组的设计并不是为了稀疏地使用

my %mem;
...
   $mem{$an} = $datum;

我要的是关联哈希,不是数组。。。我想做
$mem[$an]
嗯,我想要一个关联哈希,而不是数组。。。我想做
$mem[$an]
$an最初是如何设置的?您实际上有2G元素,还是数组稀疏?如果是前者,则需要一个64位的Perl构建。如果是后者,考虑使用更合适的数据结构(至少是哈希)。$a是如何设置的?你实际上有2G元素,还是数组稀疏?如果是前者,则需要一个64位的Perl构建。如果是后者,考虑使用更合适的数据结构(至少是哈希)。