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.
|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|