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

The END (and the CHECK?) would have to be at the end of the code, not the beginning. Maybe they should be in an eval "" at the end of your script, because they're done Last Encountered, First Executed order.

Replies are listed 'Best First'.
Re^4: Which phase am I in?
by mojotoad (Monsignor) on Nov 19, 2004 at 17:04 UTC
    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

      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.