Perl 试图修改不可创建的数组值,下标-2147483648
我对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)时,问题出现了。因此,这看起来
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构建。如果是后者,考虑使用更合适的数据结构(至少是哈希)。