What is $@ in Perl?

前端 未结 2 614
有刺的猬
有刺的猬 2021-01-02 07:50

I have a Perl script which I cannot understand.

for $i(@myarr)
{
    #some stuff
    eval {
        #some stuff
    };
    if($@)
    {
        print \"*** $         


        
相关标签:
2条回答
  • 2021-01-02 07:54

    $@ The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval. please read this doc http://perldoc.perl.org/perlvar.html

    0 讨论(0)
  • 2021-01-02 08:11

    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).

    0 讨论(0)
提交回复
热议问题