本文介绍了Perl 中的 $@ 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我看不懂的 Perl 脚本.
I have a Perl script which I cannot understand.
for $i(@myarr)
{
#some stuff
eval {
#some stuff
};
if($@)
{
print "*** $@ ****";
}
}
- 那个 eval 有什么作用?它是标准 Perl 命令还是只是一些子命令?
- 变量 $@ 是什么?它目前正在打印一个字符串,但我不知道该字符串来自哪里.
推荐答案
要添加到 Suic 的答案,请参阅 英文 模块,让您使用更具描述性的 $EVAL_ERROR
而不是 $@
和 Try::Tiny 或 TryCatcha> 避免与使用 eval
进行异常处理相关的常见陷阱的模块.另外,下次您想知道 Perl 函数时,perldoc -f
是您的朋友(例如 perldoc -f eval
).
To add to Suic’s answer, see the English module that lets you use more descriptive $EVAL_ERROR
instead of $@
and the Try::Tiny or TryCatch modules that avoid common traps associated with using eval
for exception handling. Also, the next time you wonder about a Perl function, perldoc -f
is your friend (like perldoc -f eval
).
这篇关于Perl 中的 $@ 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!