我正在用Perl写一个程序。我在一个循环中调用一个sub。在调用子程序之后,程序停止循环遍历@list中的其余值。有任何想法吗?Perl之后的Perl循环问题?
for($i = 0; $i <@list; i++){
if($value{attrs[$i]} ne $otherValue{otherAttrs[$i]}){
$convert = valueConvert(otherValue{otherAttrs[$i]};
$value{attrs[$i]} = $convert;
}
}
这是次
sub valueConvert{
($mValue) = @_;
....
return $mValue
}
的值正确地转换在子并返回到主循环,并正确分配。所以我不知道什么是错的
在EVERY中包含['use strict;'](http://perldoc.perl.org/strict.html)和['use warnings'](http://perldoc.perl.org/warnings.html) perl脚本。这很可能是你问题的根源,但是你不能提供足够的信息来确定诊断。 – Miller 2014-10-30 16:58:07
您还应该添加一些打印语句来调试问题。打印@list的大小,然后每次循环尝试打印'$ i'。这将告诉你,如果它正在通过每一次迭代。我的猜测是它经历了每一次迭代,但是你的'if()'语句每次都没有返回“true”,所以它似乎在跳过一些东西。 – tjwrona1992 2014-10-30 17:02:42