Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 在不退出的情况下处理所有文件_Perl - Fatal编程技术网

Perl 在不退出的情况下处理所有文件

Perl 在不退出的情况下处理所有文件,perl,Perl,我正在实现一些东西,需要检查变量的值是否已定义,然后继续退出代码。我把这个逻辑保存在一个脚本中,它必须检查在perforce客户端上打开的所有文件 eval { $test = $temp->project($loc); }; unless ($test){ print "undefiled value.please check.\n\n"; exit(1); } 在我的perforce客户端上打开的其他文件需要验证。这

我正在实现一些东西,需要检查变量的值是否已定义,然后继续退出代码。我把这个逻辑保存在一个脚本中,它必须检查在perforce客户端上打开的所有文件

 eval { $test = $temp->project($loc); };
    unless ($test){
       print "undefiled value.please check.\n\n";
       exit(1);
     }
在我的perforce客户端上打开的其他文件需要验证。这里我的脚本在看到第一个问题时退出。 在这里,我想通过验证客户端上所有打开的文件来显示所有问题。
有什么建议吗?

我想你应该把代码改成这样:

# Before your loop, set up a variable to store errors
my @errors;

# Where your code is
eval { $test = $temp->project($loc) };

unless ($test) {
  # Don't exit, but store the error and move to the next iteration
  push @errors, "Undefiled value <$loc>. Please check.\n\n";
  next;
}

# After your loop, die id there are any errors
die join "\n", @errors if @errors;
#在循环之前,设置一个变量来存储错误
我的错误;
#你的代码在哪里
eval{$test=$temp->project($loc)};
除非($测试){
#不退出,但存储错误并移动到下一个迭代
推送@errors,“未定义的值。请检查。\n\n”;
下一个
}
#循环结束后,如果有任何错误
死联接“\n”,如果@errors,则为@errors;
更新:我喜欢评论中的建议

# Before your loop, set up a variable to count errors
my $errors;

# Where your code is
eval { $test = $temp->project($loc) };

unless ($test) {
  # Don't exit, but store the error and move to the next iteration
  warn "Undefiled value <$loc>. Please check.\n\n";
  ++$errors;
  next;
}

# After your loop, die id there are any errors
exit(1) if $errors;
#在循环之前,设置一个变量来计算错误
我的错误;
#你的代码在哪里
eval{$test=$temp->project($loc)};
除非($测试){
#不退出,但存储错误并移动到下一个迭代
警告“未定义的值。请检查。\n\n”;
++$errors;
下一个
}
#循环结束后,如果有任何错误
退出(1)如果$errors;

是的,将您的错误推入数组,并在所有检查之后执行
die()+
警告(…)++$错误;其次+
退出(1)。更灵敏、更耐碰撞。