Compile time and Run time in perl

╄→гoц情女王★ 提交于 2019-12-03 09:04:25

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:

  1. Compile script.pl
    1. Compile use Foo;
    2. Execute require Foo;
      1. Compile Foo.pm
        1. ...
      2. Execute Foo.pm
        1. ...
    3. Execute import Foo;
    4. Compile my $foo = Foo->new();
    5. Compile $foo->do();
  2. Execute script.pl
    1. Execute my $foo = Foo->new();
    2. Execute $foo->do();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!