IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New I'll report that as a misfeature
I read more documentation. You're right that it is listed as a feature, see perlvar. However you're right that it is very inconvenient. I'll suggest that that should be changed.

If you call exit with a value, you're absolutely right that you probably want to exit with that value. So Perl should set $? just before you exit.

In the meantime you have 2 options. The first is to use POSIX and then call POSIX::_exit. This will skip all DESTROY and END blocks. The other is to make the following module the very first thing that you use. It will fix this bug.
\npackage FixExit;\nmy $exit_value;\nEND {\n$? = $exit_value if defined($exit_value);\n}\n\nsub my_exit {\n$exit_value = shift;\nCORE::exit();\n}\n\n*CORE::GLOBAL::exit = &my_exit;\n

(The latter is probably the best solution.)

Cheers,
Ben

PS This is something that was changed in the 5.8 series. In 5.6 and before, exit() did not run END blocks so the question never arose. Undoubtably someone made the change, thought that overriding $? in END blocks could be useful, and nobody thought about the fact that $? is set implicitly in lots of places, leading to surprising behaviour.
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
Expand Edited by ben_tilly Nov. 3, 2005, 11:19:12 AM EST
Expand Edited by ben_tilly Nov. 3, 2005, 11:42:26 AM EST
New Slightly more than that
Turns out that destructors (DESTROY) of objects are executed _after_ END blocks, so I had to have an Ender class declared, and use an instance of that class, allocated fairly early in the code to exit.

------

179. I will not outsource core functions.
--
[link|http://omega.med.yale.edu/~pcy5/misc/overlord2.htm|.]

New Ah. Missed that detail.
Please note that reliable destruction order during global destruction was only recently added to Perl, so that strategy is only truly reliable on very recent versions of Perl.

This is definitely a misfeature. :-(

Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New 5.8

------

179. I will not outsource core functions.
--
[link|http://omega.med.yale.edu/~pcy5/misc/overlord2.htm|.]

New /me checks the change history...
And finds that reliable destruction order was added in 2000, so all 5.8 releases have it.

Note that, until 5.8, exit() did not run DESTROY or END blocks. So your problem would not have existed then. (But you didn't get the chance to do cleanup that you might want to.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
     Larry Wall thinks it's a feature - (Arkadiy) - (6)
         I'll report that as a misfeature - (ben_tilly) - (4)
             Slightly more than that - (Arkadiy) - (3)
                 Ah. Missed that detail. - (ben_tilly) - (2)
                     5.8 -NT - (Arkadiy) - (1)
                         /me checks the change history... - (ben_tilly)
         Punishment for trying OOP in Perl? -NT - (tablizer)

It’s an insidious time-gobbler.
111 ms