Search code examples
perlevalperlvar

What does the special variable $@ mean in Perl?


I'm trying to understand the following piece of code:

sub foo {
    ...
    if ( $@ ) {
        ...
        die $@;
    }
}

Solution

  • perldoc -f eval:

    If there is a syntax error or runtime error, or a "die" statement is executed, an undefined value is returned by "eval", and $@ is set to the error message. If there was no error, $@ is guaranteed to be a null string.

    See also perldoc perlvar.