Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

$! or $?

by CiceroLove (Monk)
on Jan 31, 2001 at 01:17 UTC ( #55358=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://55358]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2021-06-22 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (108 votes). Check out past polls.

    Notices?