I'm not completely happy with most documentation I see on "compile time" and "run time". They mostly encourage or at least don't discourage the impression that there is one time called "compile time" when your script is compiled and then there is one "run time".
In reality, each statement has its own "compile time" and any number of "run time"s.
I find it clearer and more accurate to think about more detailed steps that perl goes through, in order.
- Reads the next line of source code.
- Compiles the next complete statement (if there is one)
- Performs any "compile-time" actions for that statement
- Go to (2) if there are more complete statements already read
- Go to (1) if there are more lines to be read from the current source file
- Run INIT blocks from the current source file
- If the current source file is the main script, then run all CHECK blocks
- Start running at the first statement (of the current source file) that is not part of a subroutine
- Continue running until "falling off the end" of the current source file
- Go to (1) on the previous source file if there is one
So, if I use require in my main script, then there can be whole files of Perl code that don't get compiled until after my main script has finished being compiled and has started running (and the require statement might not even get run).
Conversely, if I use that same require statement inside of a module that my main script uses, then those files will be compiled and their non-subroutine statements run before most of my main script is even compiled.
Update: s/of/off/. Thanks, gam3.
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>
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
Want more info? How to link or
or How to display code and escape characters
are good places to start.