Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: is there a way to ensure some code is the last thing that is run?

by RonW (Parson)
on Feb 06, 2017 at 20:03 UTC ( [id://1181203]=note: print w/replies, xml ) Need Help??


in reply to Re^2: is there a way to ensure some code is the last thing that is run?
in thread is there a way to ensure some code is the last thing that is run?

Morgon, interesting discussion you started.

I think the best you can do is to focus on "seen first, run last" and "end of scope".

Using those 2 points, I think the following is the closest to what you are asking for.

#!perl # Make this END block the first thing compiled to insure it # will be the last END block to run. END { # any special clean up goes here warn 'END - Bypassing final global Perl clean up'; # $? is the value passed to exit() unless modified # in another END block. POSIX::_exit($?); # WARNING - Any DESTRUCTions that could not be # completed before _exit() is called will NOT # be completed } # Create an extra layer of scope { use strict; use warnings; use Some::Module; my $s = Some::Module->new(); } # Close extra scope to trigger most of the DESTRUCTion exit(0); # Here, the various END blocks will run in reverse order # of being compiled, concluding with the END block at the # top of this file.

Disclaimer: Not tested. YMMV.

  • Comment on Re^3: is there a way to ensure some code is the last thing that is run?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1181203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-18 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found