in reply to Re^7: Which phase am I in?
in thread Which phase am I in?
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:
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.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 }
And yes, that might mean that you put an END block at the beginning of your code. That's not wrong.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Which phase am I in?
by ikegami (Patriarch) on Nov 19, 2004 at 20:02 UTC | |
by tilly (Archbishop) on Nov 19, 2004 at 21:27 UTC |