Perhaps Tilly was thinking of POSIX::_exit which was muted (by me, though previously by another) but as a possibly workaround to a different problem.

On package constructors/destructors point, I realise the nature of the beast, and if you accept that such implicit destructors are a 'Good Thing', then I agree that there is some merit in their being called in LIFO order between the packages. Clumbsily stated, but I mean that the END blocks of the first encountered package (generally main) should be called last. Those of the second package encountered--generally the first use statement within main--should be called second from last. Those of the third package encountered--perhaps the first use statement within the first package called from main--being called third from last. And so on through the package hierachy.

But I still find it counter-intuative that the END blocks within any given package will be called in the reverse of their physical ordering in the code, and even worse, that I would have to place the END block(s) in my code, be it main or package, before any use statements in that same package, in order to ensure that my code gets it's final opportunity to clean up after those subordinate packages it calls.

If I were sitting down to design the END block processing from scratch, I would combine the END blocks within a package in their natural ordering, and call these combined destructors in the LIFO order of which the packages came into existance. That's probably too complex, but it seems like the 'right way' to do it to me.

Generally, I think that reliance on automatic destructors is a bad thing, and that every package should offer me a call that allows me to inform them when I have finished with them. The END block for that package could then test to see if I have done the right thing, and only call the destructor if I haven't.

At the end of the day, my opposition to the current mechanism is purely academic as I have rarely ever used END blocks, and never in anger. And as Tilly pointed out, I've also never heard of anyone who has actually fallen foul of the problem I perceive, and so this is likely just (another) load of hot air on my behalf. That does lessen the strength of my feelings against the status quo though, and I would still consider it to be a bug. Or at least, consider any code that replied upon intimate knowledge of the order in which they called as a bug, because if one person can write code that relies upon this, then two can, and eventually the two pieces of code will come together, and there is no way to have both called last.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: Re^4: Execution order of END/CHECK vs BEGIN/INIT (exit??) by BrowserUk
in thread Execution order of END/CHECK vs BEGIN/INIT by belden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.