With apologies, because I'm sure my question has already been answered but I'm too dense to recognize that fact... :)

If module A "uses" module B, then you want module A's BEGIN block to run before modules B's BEGIN block. When cleanup happens, you want module B's END block to run before module A's END block.

Given these modules

# this is A.pm package A; BEGIN { print "Haven't used B yet\n" } use B; BEGIN { print "Just used B\n" } END { print "Exiting A\n" } 1; # this is B.pm package B ; BEGIN { # open a file or exit(1) with a message to STDERR open B_FH, 'somefile' or exit warn "somefile: $!\n" ; } END { close B_FH ; print "Exiting B\n" ; } 1;

If I read your post correctly, you're saying that I want module B's END block to run before module A's END block. If this is what I wanted, I think I'd be disappointed: A use's B, which means that 'use B' in A causes us to fully parse B before finishing parsing A. Therefore, B's END block is loaded before A's END block. This makes A's END block Last In, thereby First Out.

The truth is, I actually don't care in which order ENDs and CHECKs get called. I just want to know why BEGIN/INIT are FIFO and END/CHECK are LIFO.

blyman
setenv EXINIT 'set noai ts=2'

In reply to Re: Re: Re: Re: Execution order of END/CHECK vs BEGIN/INIT by belden
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.