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.
| [reply] |
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. | [reply] [d/l] |
So if your initialization and cleanup code are related,
They're not, at least not in the sense you mean. Read the thread. We can't use the normal case here. We want to set $phase as early as possible after BEGINs start being processed, and we want to set $phase as early as possible after ENDs start being processed. BEGIN is FIFO. END is LIFO. We want FO for both, so we need to put BEGIN as FI as possible, and the END as LI as possible.
| [reply] |