"be consistent" | |
PerlMonks |
BEGIN vs initializationby Wiggins (Hermit) |
on Nov 28, 2009 at 20:32 UTC ( [id://809940]=perlquestion: print w/replies, xml ) | Need Help?? |
Wiggins has asked for the wisdom of the Perl Monks concerning the following question: I want to use a BEGIN block to set a global context variable that other modules will use to adjust their control flow. But I remember the C++ "static initialization" pattern, which ran code before 'main' was called. The question is When I began this 2 years ago, I could find no good documentation on the pragma "vars" other than "it pre-allocates global variables". That really says nothing about scope, mechanics, accessibility,... But I did get 'our' to work, and I like the explicit "Gbl::" prefix as self documentation. This is the module of global values.
This is the main controlling file (which will 'use Gbl;"
If the initialization executes immediately after parse, then
The initializers had not yet run in Gbl to define the variables at the point when main.pl's BEGIN block runs and accesses them? It is always better to have seen your target for yourself, rather than depend upon someone else's description.
Back to
Seekers of Perl Wisdom
|
|