I read up on some of the documentation on END and I think the answer to your problem is pretty simple. According to perlmod: END {} blocks are executed in reverse order. The last END created is the first END that gets executed. It seems all you need to do is define your END {} at the very beginning of your program before the other ones get defined. That should allow you to set your $? variable to whatever you want since by the time its seen all of the modifications to it should have already happened.
use is really just a BEGIN {} block and BEGIN executes in the order its seen. You could create a module that has your final end block and use it the very first. Tell it to redefine $? to some other value. use all of your other modules then at the end of all that use another module that creates an END { } that saves the original exit value from the program. Something like this:
#!/usr/bin/perl use strict; use vars qw($myexitvalue); use MyLastEnd; use Foo; use Bar; use SomeOtherModule; use MyFirstEnd; # rest of script #MyLastEnd.pm END { $? = $myexitvalue; } #MyFirstEnd.pm END { $myexitvalue = $?; }
All of this is untested of course, but if I'm reading the docs right it *should* work. Hope that helps!
In reply to Re: Getting around $? setting in END blocks
by cfreak
in thread Getting around $? setting in END blocks
by DrWhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |