I know what they all do, but have never found myself in a situation where I’ve needed any of them. I’ve used BEGIN blocks on many occasions and ENDs once in a while. BEGIN is especially useful when you need to tweak the environment before code gets run, and I’ve used END in certain debugging situations to trap important state information for hard-to-track-down fatal errors.
Have you ever used CHECK, UNITCHECK or INIT? If so, what for? And would a BEGIN block not have sufficed for some reason?
The documentation for the blocks is on PerlDoc.
I had a package
importfunction which would do some heavy duty processing and then make anevalcall. How do you debug something like that? The import function gets run when youusethe module, which takes place at compile time (like it was inside a BEGIN block). For some reason (I think it was because I needed to pass parameters toimportwith heredoc notation, but it could have been something else), it wasn’t good enough to sayrequire Module; Module->import(@args).So my workaround was to build the string for
evalinimport, and save it another variable.Then I ran the
evalin anINITblock. When you ran the debugger, the very first execution point was at the start of theINITblock and I could use the debugger to step through theevalstatement.