CiceroLove has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone point me to a quick table of what functions errors into which of the two variables, $! or $?. I always get confused and it makes me spiritually angry.

Replies are listed 'Best First'.
Re: $! or $?
by kschwab (Vicar) on Jan 31, 2001 at 01:28 UTC
    See perlvar, it's pretty clear.

    $! aka $ERRNO If used in a numeric context, yields the current value of errno, with all the usual caveats. $? aka $CHILD_ERROR The status returned by the last pipe close, backtick(``) command, or system() operator. $@ aka $EVAL_ERROR The Perl syntax error message from the last eval() command
    So unless the error is in the context of starting a new process, or an eval(), it's $! you want.

    One possible exception: Modules may use some variable or method of their own to expose errors. See the docs for the module.

Re: $! or $?
by c-era (Curate) on Jan 31, 2001 at 01:24 UTC
    $! - os error - from the last system call (not to be confused with 'system()')

    $? - child error - The status returned by the last pipe close ('`', 'system()')

    '`' and 'system()' create child processes that run and terminate. $? contains their exit status. Other calls ('open()', 'close ()',etc.), make system calls, and $! contains the status of the last system call.

Re: $! or $?
by dkubb (Deacon) on Jan 31, 2001 at 12:21 UTC