Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: mod_perl and imports

by Eily (Vicar)
on Sep 27, 2013 at 11:44 UTC ( #1055970=note: print w/replies, xml ) Need Help??

in reply to Re: mod_perl and imports
in thread mod_perl and imports

It will actually be run straightaway, as soon as the block is reached by the compiler. So whatever lines are below the BEGIN { } won't have even been seen at the time of its execution.

Replies are listed 'Best First'.
Re^3: mod_perl and imports
by Marshall (Abbot) on Sep 30, 2013 at 08:03 UTC

    A BEGIN code block is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed. You may have multiple BEGIN blocks within a file (or eval'ed string); they will execute in order of definition. Because a BEGIN code block executes immediately, it can pull in definitions of subroutines and such from other files in time to be visible to the rest of the compile and run time. Once a BEGIN has run, it is immediately undefined and any code it used is returned to Perl's memory pool.
    So, yes, a BEGIN block will run when it is encountered. But it will only run once - that part of my statement is correct. But it does appear that you can intersperse BEGIN blocks within the code and they will run essentially as the code "compiles". that is cool Perl thing.

    When I have used BEGIN{}, I have never interspersed these within the code, but rather have put these at the "end" of the code. In other words, this is initialization code that should be executed before the main code - not interspersed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055970]
[stevieb]: I'm learning that no matter how good a piece of software is at what it's supposed to do, it's a piece of shit without providing any API documentation. (Talking about C++ here currently). Seriously... write software for an embedded platform and make...
[stevieb]: guess based on the sparse examples, and the header files that are spread out illogically?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-05-28 23:41 GMT
Find Nodes?
    Voting Booth?