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

In my crash course Perl lesson of porting a decade plus old application running on a Unix server to run on a Windows 2003 server, I have made extensive use of Google to resolve and learn about features of the code with which I was unfamiliar.

This has generally worked well for me, but is failing in this one regard. In several places in the code there is a reference to $?. It is almost always after a system call using the open() function, usually to SQL*Plus in this application's case. It seems to be involved in exception handling as it is generally used in code such as this:

$v_error = $?/256; if ($v_error) {...}

So can somebody kindly point me to or provide a basic understanding on what $? is actually referencing I would really appreciate it. What does this actually do under the hood. I have found that searching Google for a '?' to be rather fruitless.

Thank You

Replies are listed 'Best First'.
Re: $? What does this reference?
by kyle (Abbot) on Apr 09, 2008 at 19:10 UTC

    You can find this documented in perlvar along with all the other punctuation variables. The beginning of the description for $? is:

    The status returned by the last pipe close, backtick (``) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it).
Re: $? What does this reference?
by FunkyMonk (Bishop) on Apr 09, 2008 at 19:11 UTC
    From perlvar:
    The status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ($?>> 8 ), and $? & 127 gives which signal, if any, the process died from, and $? & 128 reports whether there was a core dump. (Mnemonic: similar to sh and ksh.)
    You can access the full range of Perl's extensive documentation from the command line by using perldoc or via the interweb by googling for "perldoc whatever" or via the start menu if you're using activestate or ...

Re: $? What does this reference?
by locked_user sundialsvc4 (Abbot) on Apr 09, 2008 at 20:55 UTC

    “Larry Wall can't type.”

    Or maybe it's just an example of the supposedly-admirable quality of “laziness.” Anyhow, Perl is unfortunately full of a full set of these “chicken scratch” variables, and they are quite an entrenched part of the language. More-or-less on par with the MIT Lisp-hackers of yore who used to go around saying to one another: “food-p?” ... confident that no one else would understand what they were talking about, and snickeringly proud of it.

      “Larry Wall can't type.”
      Actually, the $? variable derives from shell syntax

      Dave.

      Everybody knows the much funnier joke is split-p soup?