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:
perl my_script.pl
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 a require
and possibly a import
.
For example,
# script.pl
use Foo;
my $foo = Foo->new();
$foo->do();
Does:
- Compile
script.pl
- Compile
use Foo;
- Execute
require Foo;
- Compile
Foo.pm
- ...
- Execute
Foo.pm
- ...
- Compile
- Execute
import Foo;
- Compile
my $foo = Foo->new();
- Compile
$foo->do();
- Compile
- Execute
script.pl
- Execute
my $foo = Foo->new();
- Execute
$foo->do();
- Execute
来源:https://stackoverflow.com/questions/14766878/compile-time-and-run-time-in-perl