in reply to Run before exit

You could use an END block or $SIG{__DIE__} and then use caller to find out if you're END'ing or DIE'ing from an exit call.

Replies are listed 'Best First'.
Re^2: Run before exit
by Delusional (Beadle) on Jun 17, 2008 at 10:35 UTC
    Thanks. This got me on the right track. Simply adding a sub END { } did the trick. I had to change the ending sub to set a var, and only execute if the var wasn't set though. Waisted memory and not really the cleanest way, and I, possibly, could have put the entire ending sub in the END sub, but it works.

    The original ending sub was all that needed to be executed as its basically a 'clean-up and close loose ends' function (database, file handlers, html footers, etc.).

    I intentionally placed exit calls in bad places to test if all was working correctly, and it did with sub END { }, but 'failed' (because the ending sub was not executed) without it.