我是 perl 新手,似乎无法在任何地方找到有关此问题的答案。我将问题缩小到递归函数。如果我将其注释掉,那么它可以正常工作而没有错误。我有:
use strict;
use warnings;
sub GeneratePermutations{
my($n, $nMax, $i, $ArrLength, @Arr) = @_;
if($n == 0){
foreach($i..$ArrLength-1){
$Arr[$i] = 0;
++$i;
}
my @qArr = ();
my $rVal = 1;
for(my $p = 0; $p < @Arr; $p++){
$rVal *= fac($Arr[$p]);
for(my $q = 0; $q < $ArrLength; $q++){
my $qCount = 0;
for(my $j = 0; $j < $ArrLength; $j++){
if($Arr[$j] eq $q){
++$qCount;
}
}
$qArr[$i] = $qCount;
}
}
my $qVal = 1;
for(my $qNum = 0; $qNum < @qArr; $qNum++){
$qVal *= fac($qArr[$qNum]);
}
my $maxDistVal = 0;
$maxDistVal = (1/($ArrLength**$ArrLength))*(fac($ArrLength)/$rVal)*(fac($ArrLength)/$qVal);
if($maxDistVal > $distribution){
$distribution = $maxDistVal;
}
#prints out distributions for all permutations (comment out previous if-statement)
print "Dist: " . $distribution . "<br /><br />";
#return 1;
}
my $resultCnt = 0;
for(my $cnt = MinVal($nMax, $n); $cnt > 0; $cnt--){
$Arr[$i] = $cnt;
++$resultCnt;
GeneratePermutations(int($n-$cnt), $cnt, $i+1, $ArrLength, @Arr);
}
#return $resultCnt;
return $distribution;
}
我错过了什么?