Now I have no idea how it got 25856 from 101 (well it does seem to be 101 times that magical 256 number, but I'm sure it isn't that simple).

Yes, it's that simple. perlvar explains that $? is set like explained in system where the following snippet is copied from:

Quote from system:

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; }
HTH

Update:

Bit# 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 | | | | | | | | | | | | | | | | X7 X6 X5 X4 X3 X2 X1 X0 CD S6 S5 S4 S3 S2 S1 S0 | | | +-- exit code (8bit) | +-- signal code (7bit) | +-- core-dumped flag

Update2 (in response to node below):

So for quick and dirty every day use it sounds like I can just say something like: $exit_status = $?/255;
No.
my $exit_status = int( $? / 256 ); # quick and dirty exit-state # decimal arithmetic so to speak # (works for positive numbers)
Use int() to get rid of potential fractional parts when the process terminated due to a signal or core-dump.
The >>-operator does this in a single step.
I might note, that I assumed a *NIX background. The Windows emulation might not cover the whole interface (exit-code plus signals). Other monks will know better...

So X >> Y is most of the time int( X / (2**Y) ) for positive numbers.

Here are some starters for binary arithmetic: wikibooks, Khan Academy - Binary Numbers, Slideshare - Binary Arithmetic, ... Search also MIT OpenCourseWare - I am sure, they have something in their repertoire.


In reply to Re: getting the bash exit code by Perlbotics
in thread getting the bash exit code by xorl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.