Your questions don't make sense because there's no initialisation in Perl in the sense that you're picturing. Here's what you are missing:
- "=" doesn't denote an initialiser in Perl. It's always just a normal assignment.
- BEGIN blocks are executed as soon as they are compiled.
- use Module; is the same as BEGIN { require Module; import Module; }.
- Using require to load a file simply runs it as any other script (if it's not already loaded). It is both compiled and executed.
Taking a simplified version of your code
#main.pl
use Gbl;
BEGIN{
$Gbl::runContext = $Gbl::runSMTP;
}
...
# GBL.pm
package Gbl;
our $runSMTP = 2
1;
Let's apply what I've said above to determine the order in which everything is executed
main.pl |
- Compile the code.
- use Gbl; is compiled.
- use Glb; is executed. (BEGIN blocks are executed as soon as they are compiled.)
- require Gbl; is executed.
Gbl.pm |
- Compile the code.
- package Gbl; is compiled.
- our $runSMTP = 2; is compiled.
- 1; is compiled.
- Execute the code.
- our $runSMTP = 2; is executed. (This is where 2 is assigned to $runSMTP.)
- 1; is executed.
|
- import Gbl; is executed.
- BEGIN { ... } is compiled.
- $Gbl::runContext = $Gbl::runSMTP; is compiled.
- BEGIN { ... } is executed. (BEGIN blocks are executed as soon as they are compiled.)
- $Gbl::runContext = $Gbl::runSMTP; is executed. (This is where 2 is assigned to $runContext.)
- The rest of the program ("...") is compiled.
- Execute the code.
- The rest of the program ("...") is executed.
|