in reply to Re^2: Hints for getting this perly...
in thread Hints for getting this perly...
In this case the BEGIN basically causes the line initializing $output_dir to be executed before the sub that uses it gets called; without it, you'd have to rearrange the source code so that the initialization happened lexically before the first call to the sub. This is no big deal, at least in this case, but I like the freedom to arrange my code that the BEGIN trick allows. Combined with the enclosing block (around both the BEGIN block and the definition of process) it gives you something similar to (in fact better than) a C static variable. This is discussed at length here1.
1NB: in that thread I advocated using INIT blocks instead of BEGIN blocks, a position that was strongly challenged by ihb and ikegami. Since then I have learned that INIT blocks are broken, so I no longer recommend them.
the lowliest monk
|
|---|