Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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
  1. Compile the code.
    1. use Gbl; is compiled.
    2. use Glb; is executed. (BEGIN blocks are executed as soon as they are compiled.)
      1. require Gbl; is executed.
        Gbl.pm
        1. Compile the code.
          1. package Gbl; is compiled.
          2. our $runSMTP = 2; is compiled.
          3. 1; is compiled.
        2. Execute the code.
          1. our $runSMTP = 2; is executed. (This is where 2 is assigned to $runSMTP.)
          2. 1; is executed.
      2. import Gbl; is executed.
    3. BEGIN { ... } is compiled.
      1. $Gbl::runContext = $Gbl::runSMTP; is compiled.
    4. BEGIN { ... } is executed. (BEGIN blocks are executed as soon as they are compiled.)
      1. $Gbl::runContext = $Gbl::runSMTP; is executed. (This is where 2 is assigned to $runContext.)
    5. The rest of the program ("...") is compiled.
  2. Execute the code.
    1. The rest of the program ("...") is executed.


In reply to Re: BEGIN vs initialization by ikegami
in thread BEGIN vs initialization by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (6)
    As of 2014-08-30 01:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (290 votes), past polls