Compilation time and runtime in perl

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

I can not understand when the RUN time and when COMPILE time events occur when running the perl script on the command line as follows:

perl my_script.pl 
+4
source share
1 answer

perl script.pl will compile script.pl , then execute script.pl . Similarly, require Module; will compile Module.pm , then execute Module.pm .

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 require and possibly a import .

For instance,

 # script.pl use Foo; my $foo = Foo->new(); $foo->do(); 

whether:

  • Compile script.pl
    • Compile use Foo;
    • Run require Foo;
      • Compile Foo.pm
        • ...
      • Run Foo.pm
        • ...
    • Run import Foo;
    • Compile my $foo = Foo->new();
    • Compile $foo->do();
  • Run script.pl
    • Run my $foo = Foo->new();
    • Run $foo->do();
+13
source

All Articles