[英]Compile time and run time in Perl
I am reading this document to understand the life cycle of a Perl program.我正在阅读本文档以了解 Perl 程序的生命周期。
When do run time and when do compile time events occur while running a Perl script on a command line like this:在命令行上运行 Perl 脚本时,何时会发生运行时和编译时事件,如下所示:
perl my_script.pl
perl script.pl
will compile script.pl
then execute script.pl
. perl script.pl
将编译script.pl
然后执行script.pl
。 Similarly, require Module;
同样,
require Module;
will compile Module.pm
then execute Module.pm
.将编译
Module.pm
然后执行Module.pm
。
If the compiler encounters a BEGIN
block, it will execute the block as soon as the block is compiled.如果编译器遇到
BEGIN
块,它会在块被编译后立即执行该块。 Keep in mind that use
is a BEGIN
block consisting of a require
and possibly a import
.请记住,
use
是一个BEGIN
块,由一个require
和一个可能的import
。
For example,例如,
# script.pl
use Foo;
my $foo = Foo->new();
$foo->do();
Does:做:
script.pl
script.pl
use Foo;
use Foo;
require Foo;
require Foo;
Foo.pm
Foo.pm
Foo.pm
Foo.pm
import Foo;
import Foo;
my $foo = Foo->new();
my $foo = Foo->new();
$foo->do();
$foo->do();
script.pl
script.pl
my $foo = Foo->new();
my $foo = Foo->new();
$foo->do();
$foo->do();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.