Hi,

Testing this shows that it appears to work, even for compile-time* errors:

$ cat ex.pl #!/usr/bin/env perl use warnings; use strict; END { $? = 250 if $? == 255 } print $c; $ perl ex.pl ; echo $? Global symbol "$c" requires explicit package name (did you forget to d +eclare "my $c"?) at ex.pl line 7. Execution of ex.pl aborted due to compilation errors. 250

Note this is documented in $?. However, this solution means you'd have to insert the END block at the top of every script that you run like this, so personally I like Corion's suggestion of a wrapper script better. Also, consider what kind of errors you are catching. Syntax errors are something that you can catch when you're developing the script, so I don't see how those could sneak in. Runtime errors, like you mention in the bug report accessing something that doesn't exist, are something you could catch and handle gracefully within the script, for example there's Try::Tiny.

* Update: Actually I think this may be inaccurate, although it seems to catch many syntax errors and such, there might be cases where the END block isn't executed; if I get around to it I'll test more later.

Hope this helps,
-- Hauke D


In reply to Re^2: 255: perl compilation error code and ssh cannot connect code (updated) by haukex
in thread 255: perl compilation error code and ssh cannot connect code by i5513

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.