Arrays 迭代数组引用会导致无限循环

Arrays 迭代数组引用会导致无限循环,arrays,perl,loops,Arrays,Perl,Loops,我有以下方法: sub CleanErrorLog { my ($actnList, $cmplist) = @_; print "\n" . ("-" x 100) . "\n"; print "\t\t---->> Begin Clean Error Output <<----"; for my $comp (@$cmplist) { for my $action (@$actnList) { Build

我有以下方法:

sub CleanErrorLog {
  my ($actnList, $cmplist) = @_;


  print "\n" . ("-" x 100) . "\n";
  print "\t\t---->>  Begin Clean Error Output  <<----";
  for my $comp (@$cmplist)
  { 
    for my $action (@$actnList)
    { 
        Build($comp, $action);
    }
  }
}

然而,循环永远不会结束——它不断地尝试
构建($comp,$action)
。这是我第一次使用
\@
作为参数,所以我可能做错了什么?

您的
构建
函数可能修改了
@actionList
@failedComponents
数组。当您通过引用传递数组时,这些修改可能会导致无限循环。作为一条指导原则,永远不要修改正在迭代的数组或散列。总是先复印一份。例如,您可以将副本传递到
CleanErrorLog

CleanErrorLog([@actionList], [@failedComponents]) if @failedComponents;

更好的解决方案是重新编写
构建
,这样就不会修改这些变量。

每个列表中有多少项?同样对于调试,使用打印语句替换生成函数调用,在打印语句中打印这两个变量。对于调试:它是否与
CleanErrorLog([@actionList],@failedComponents])
一起工作?在这种情况下,
Build
将修改
@actionList
@failedComponents
,这可能会导致无限循环。这里没有无限循环,@amon使用
[@actionList],@failedComponents]
工作-谢谢,我现在看到问题了!
CleanErrorLog([@actionList], [@failedComponents]) if @failedComponents;