Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Run before exit

by moritz (Cardinal)
on Jun 16, 2008 at 16:00 UTC ( #692294=note: print w/replies, xml ) Need Help??

in reply to Run before exit

Just add a block like this:
END { call_your_sub_here() }

Replies are listed 'Best First'.
Re: Run before exit
by b10m (Vicar) on Jun 16, 2008 at 16:02 UTC

    Wouldn't that be executed as well with die()?

      Yes. I didn't parse the "only" in the original question correctly. If it should really only be triggered by exit, it might be useful to override it (CORE::exit IIRC).
        (CORE::exit IIRC)

        Use CORE::GLOBAL::exit() to override — CORE::exit() is the original exit builtin that you'd typically call from within your redefined exit routine...

        Update: an example:

        #!/usr/bin/perl BEGIN { *CORE::GLOBAL::exit = sub (;$) { print STDERR "in overridden exit(): @_\n"; CORE::exit(88); }; } exit 99;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://692294]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-07-22 20:54 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (455 votes). Check out past polls.