Krishnachandra Sharma Krishnachandra Sharma - 1 year ago 79
Perl Question

Compile time and Run time in perl

I am reading this document to understand the life cycle of a Perl program.

I am unable to figure out when RUN time and when COMPILE time events occur while running a perl script on a command line like this:


Answer Source

perl will compile then execute Similarly, require Module; will compile then execute

If the compiler encounters a BEGIN block, it will execute the block as soon as the block is compiled. Keep in mind that use is a BEGIN block consisting of a require and possibly a import.

For example,

use Foo;
my $foo = Foo->new();


  1. Compile
    1. Compile use Foo;
    2. Execute require Foo;
      1. Compile
        1. ...
      2. Execute
        1. ...
    3. Execute import Foo;
    4. Compile my $foo = Foo->new();
    5. Compile $foo->do();
  2. Execute
    1. Execute my $foo = Foo->new();
    2. Execute $foo->do();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download