I have a script where I need to indicate success or failure via the exit value. However, I'm running into the problem that anything that sets's $? in END block overwrites your requested. There's a nice succinct discussion of this problem here (Beware $? and END).

It even includes the solution of making $? local in your END block. This won't work for me for the following reasons. I don't know where the END block is. It's buried deep in some library somewhere. This script uses currently over 100 libraries and that number is likely to grow over time. I also don't know if it's in only one place or multiple places so even if I did find one there might be others. The actual number of libraries used isn't even determined within the script itself. This script runs all the test scripts for our project (implemented within the Test::Unit framework) so as we add more modules and more tests for existing modules this is expected to grow. The END block (some of the END blocks) may well be in one of the CPAN or non-local, non-CPAN modules our modules make use of. If they aren't now then in the future one might be.

I tried to use Manip::END. Using this to push a new END block onto the list of END blocks that preserves/restoreds the desired exit value would work and be a nice local solution to this very non-local problem. But we're using 5.6.1 and Manip::END requires 5.8.0.

Anybody out there have any idea how I can get a local solution that works with 5.6.1? For instance, is it possible to get at the list of END block subroutines without Manip::END?

Much thanks!

-- DrWhy


In reply to Getting around $? setting in END blocks by DrWhy

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.