If that was your point, then you're wrong.

BEGINs are in first in, first out order and ENDs are in first in, last out order explicitly so that you can write code like this and trust the transactional semantics:

BEGIN { # initialize stuff } END { # cleanup stuff } # code passes, possibly you're in a different module now... BEGIN { # initialize other stuff, # which might depend on first stuff } END { # clean up other stuff, # clean up might depend on first stuff still being here }
So if your initialization and cleanup code are related, you are supposed to put them together, wherever they may appear in your code. That way if Perl has done the initialization, it will do its best to do the necessary cleanup as well.

And yes, that might mean that you put an END block at the beginning of your code. That's not wrong.


In reply to Re^8: Which phase am I in? by tilly
in thread Which phase am I in? by dragonchild

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.