[EMAIL PROTECTED] wrote:
ok so $? states CHILD_ERROR or last status returned by the last ` ....`
command.
$! states yields the current value of errno

in shell if I say it will give me a true or false value.

cat /tmp/foo
if [ $? -eq 0 ]
then
      echo yes command succeeded
else
      echo no.
fi

In the shell any programs that you run are child processes so 'cat /tmp/foo' is run as a child of the shell and sets $? when it ends.


In Perl if I wanted to represent this I would use $! for any notification
of any failures such as opening a file.

That is because open() is built in to perl.


 But when I add the code in red
specifically  $? >> 8,  I get a exit value of 2 and when I change it to $?

127 I get a exit value of 0. I want to understand and know the code to

get a true (1) or false (0) value.

Programs that run on the command line return 0 on success or some non-zero value on failure. Some programs return different non-zero values depending on the type of failure but the C language defines two standard return values in the stdlib.h file: EXIT_SUCCESS and EXIT_FAILURE.

perldoc -f system
[snip]
          You can check all the failure possibilities by inspecting $? like
          this:

              if ($? == -1) {
                  print "failed to execute: $!\n";
              }
              elsif ($? & 127) {
                  printf "child died with signal %d, %s coredump\n",
                      ($? & 127),  ($? & 128) ? 'with' : 'without';
              }
              else {
                  printf "child exited with value %d\n", $? >> 8;
              }

          or more portably by using the W*() calls of the POSIX extension; see
          perlport for more information.



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to