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.
|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.