Perl 中的编译时间和运行时间 [英] Compile time and run time in Perl
问题描述
我正在阅读本文档以了解 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 my_script.pl
推荐答案
perl script.pl
会编译 script.pl
然后执行 script.pl代码>.类似地,
require Module;
将编译 Module.pm
然后执行 Module.pm
.
perl script.pl
will compile script.pl
then execute script.pl
. Similarly, require Module;
will compile Module.pm
then execute Module.pm
.
如果编译器遇到BEGIN
块,它会在块被编译后立即执行.请记住,use
是一个 BEGIN
块,由 require
和可能的 import
组成.
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
.
例如
# script.pl
use Foo;
my $foo = Foo->new();
$foo->do();
是否:
- 编译
script.pl
- 编译
使用Foo;
- 执行
require Foo;
- 编译
Foo.pm
- ...
Foo.pm
- ...
import Foo;
my $foo = Foo->new();
$foo->do();
script.pl
- 执行
my $foo = Foo->new();
- 执行
$foo->do();
这篇关于Perl 中的编译时间和运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!