在评估之后Perl的$@会不会被定义?

前端之家收集整理的这篇文章主要介绍了在评估之后Perl的$@会不会被定义?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究 Mastering Perl“Error Handling and Reporting”章.在 perlvar的$@条目中,它说:

The Perl Syntax error message from the last eval() operator. If $@ is the null string,the last eval() parsed and executed correctly (although the operations you invoked may have Failed in the normal fashion).

现在我想知道eval何时可能无法正确执行,留下带有未定义值的$@.有这种情况吗?

解决方法

这是一种方法(但在你阅读它之前坐下来.;))

$@ = 123;
eval q{
  $@ = 456;
  print ">>>$@<<<\n";
  goto SKIP;
};

SKIP:
print ">>>$@<<<\n";

猜你在找的Perl相关文章