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.

  1. Reads the next line of source code.
  2. Compiles the next complete statement (if there is one)
  3. Performs any "compile-time" actions for that statement
  4. Go to (2) if there are more complete statements already read
  5. Go to (1) if there are more lines to be read from the current source file
  6. Run INIT blocks from the current source file
  7. If the current source file is the main script, then run all CHECK blocks
  8. Start running at the first statement (of the current source file) that is not part of a subroutine
  9. Continue running until "falling off the end" of the current source file
  10. 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.

- tye        


In reply to Re: RunTime & compile Time Doubt on Perl (many) by tye
in thread RunTime & compile Time Doubt on Perl by anilpal

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!
  • 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:
    & &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.