首先,
++$binsize
应该
$increm += $binsize;
push
有两种语法:
push @array, LIST
push $array_ref, LIST
您正在使用第二个,它需要对数组的引用,但您正在传递 undef 。使固定:
push $hash{$increm} ||= [], 0;
would do the trick. That said, that syntax is "highly experimental" and doesn't work with all reference to arrays. I suggest you stick to the traditional syntax.
push @{ $hash{$increm} ||= [] }, 0;
But thanks to autovivification, that simplifies to
push @{ $hash{$increm} }, 0;
But why are you using push
at all? You only ever assign one value per key, so the push
is equivalent to the following:
$hash{$increm} = [ 0 ];
Actually, it's questionable whether you want $hash{$increm}
to be an array reference at all. Do you simply want the following?
$hash{$increm} = 0;