简体   繁体   English

Perl 中的编译时间和运行时间

[英]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:做:

  1. Compile script.pl编译script.pl
    1. Compile use Foo;编译use Foo;
    2. Execute require Foo;执行require Foo;
      1. Compile Foo.pm编译Foo.pm
        1. ... ...
      2. Execute Foo.pm执行Foo.pm
        1. ... ...
    3. Execute import Foo;执行import Foo;
    4. Compile my $foo = Foo->new();编译my $foo = Foo->new();
    5. Compile $foo->do();编译$foo->do();
  2. Execute script.pl执行script.pl
    1. Execute my $foo = Foo->new();执行my $foo = Foo->new();
    2. Execute $foo->do();执行$foo->do();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM