Perhaps the cleanest solution would be the prosaic wrapper script -- have a script run first your first program, then your second program. All cleanup would of necessity be completed by your first program. The outer wrapper (gasp) doesn't even need to be perl, but could be shell or .bat or whatever is appropriate for your platform.
#!/bin/sh first_program args1 second_program args2

Alternatively, you could take advantage of the fact that END blocks are executed in the inverse order that they are defined, so if the very first END block your script encounters calls the exec, it will be the last bit of code run on cleanup. (see docs: http://www.perldoc.com/perl5.8.4/pod/perlmod.html#BEGIN%2c-CHECK%2c-INIT-and-END.



--JAS

In reply to Re: exec with cleanup by jsegal
in thread exec with cleanup by bart

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.