Perl 中的编译时间和运行时间 [英] Compile time and run time in Perl

查看:55
本文介绍了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();

是否:

  1. 编译script.pl
  1. 编译使用Foo;
  2. 执行require Foo;
  1. 编译Foo.pm
  1. ...

  • 执行Foo.pm

    1. ...

  • 执行import Foo;
  • 编译my $foo = Foo->new();
  • 编译$foo->do();
  • 执行script.pl

    1. 执行my $foo = Foo->new();
    2. 执行$foo->do();

  • 这篇关于Perl 中的编译时间和运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆