in reply to Re^3: Which phase am I in?
in thread Which phase am I in?

Um, no. Just like the BEGIN blocks do not have to be at the beginning of the code (but you might have to pay attention to scoping).

Each END block, however, will be executed in LEFE order as you describe.

Matt

Replies are listed 'Best First'.
Re^5: Which phase am I in?
by ikegami (Patriarch) on Nov 19, 2004 at 17:10 UTC

    If the END doesn't need to be at the end of the program, why does the following give the wrong answer? I stand by what I said.

    sub foo { print($__KLUDGE::phase eq 'END' ? 'END' : 'not END', $/); } # Needs to be at the beginning of the program to be reliable. BEGIN { $__KLUDGE::phase = 'BEGIN'; } # Needs to be at the end of the program to be reliable. END { $__KLUDGE::phase = 'END'; } # ... END { foo(); } # ...
      I think what he means is that even though it has to be the last END block, there might be other, non-END code after it.
        It's true that it may not need to be at the very end. The point was that it's wrong to put it at the beginning.