Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: $? $! ??????????????

0 views
Skip to first unread message

John W. Krahn

unread,
Dec 22, 2009, 3:39:39 PM12/22/09
to Perl Beginners
Aimee Cardenas wrote:
> Ok, All,

Hello,

> I'm a little confused. How does your outputs from die and print differ
> when you put either $! or $? at the end of the statement? I've been
> using $! at the end of my die statements and am afraid that I've been
> unknowingly not using the correct syntax because my code never dies!

$! and $? are just variables like any other variables that you may
create and use in your program and as such they have no effect on
whether die() or print() will work or not.


> Would someone explain the difference between these two?

perldoc perlvar
[ SNIP ]
$CHILD_ERROR
$? 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.)

... etc.
[ SNIP ]
$OS_ERROR
$ERRNO
$! If used numerically, yields the current value of the C
"errno" variable, or in other words, if a system or library
call fails, it sets this variable. This means that the
value of $! is meaningful only immediately after a failure:

... etc.

John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway

Shawn H Corey

unread,
Dec 22, 2009, 3:36:23 PM12/22/09
to Aimee Cardenas, Perl Beginners
Aimee Cardenas wrote:
> Ok, All,
>
> I'm a little confused. How does your outputs from die and print differ
> when you put either $! or $? at the end of the statement? I've been
> using $! at the end of my die statements and am afraid that I've been
> unknowingly not using the correct syntax because my code never dies!
> Would someone explain the difference between these two? I did a google
> but didn't get much help that way. I also searched for them on
> perldoc.perl.org but didn't find much there either. I guess it's kind
> of an obscure search. Much thanks in advance! :-)
>
> Aimee Cardenas
>

These special variables are explained in `perldoc perlvar`
http://perldoc.perl.org/perlvar.html


--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Aimee Cardenas

unread,
Dec 22, 2009, 3:22:00 PM12/22/09
to Perl Beginners
0 new messages