简体   繁体   English

Perl 在编译时和运行时如何反应?

[英]How does Perl react during compile time and run time?

What my understanding over this would be:我对此的理解是:

During compile time , an error is one that keeps Perl from being able to parse the file;编译期间,错误是使 Perl 无法解析文件的错误; such as a missing semi-colon.例如缺少分号。

And a run time error is an error that can not be detected until the code is run;运行时错误是在代码运行之前无法检测到的错误; such as a divide by zero error or a call to an undefined subroutine.例如除以零错误或调用未定义的子程序。

As Perl is an interpreted language, will the entire code or script be complied once and then run or will it compile for each and every line and then go for run?由于 Perl 是一种解释型语言,整个代码或脚本会被编译一次然后运行,还是会为每一行编译然后运行?

What is the explanation?解释是什么?

The program will be compiled once into an optree.该程序将被编译一次到一个 optree 中。 The optree is traversed and executed.遍历并执行 optree。

At runtime, it can happen that additional compile phases become necessary.在运行时,可能需要额外的编译阶段。 The usual culprits are string eval and delayed/dynamic loading of code units, eg require , do .通常的罪魁祸首是字符串eval和代码单元的延迟/动态加载,例如requiredo

Perl is an interpreted language, which means that both the compile phase and the run phase happen in sequence every time you attempt to start a script. Perl 是一种解释型语言,这意味着每次尝试启动脚本时,编译阶段和运行阶段都会按顺序发生。

Compiled languages on the other hand (C, Pascal, etc) separate out those two phases, and typically have an intermediate phase called linking , which joins together object files and libraries into the final executable file.另一方面,编译语言(C、Pascal 等)将这两个阶段分开,通常有一个称为链接的中间阶段,它将目标文件库连接到最终的可执行文件中。

In compiled languages, detecting an undefined function can happen in either the compile phase, or the linking phase, depending on how strict the language specification is.在编译语言中,根据语言规范的严格程度,可以在编译阶段或链接阶段检测未定义的函数。 In original C calling an undefined function would be found by the linker, but in C++ it would be found by the compiler.在原始 C 中,链接器会发现调用未定义的函数,但在 C++ 中,它会被编译器发现。

To further complicated matters, some languages such as Java have separate compile and execution phases, but the compilation is actually to an intermediate "byte code", which is then interpreted by a run time system (ie the Java Virtual Machine).为了进一步复杂的事情,一些语言如Java有单独的编译和执行阶段,但编译实际上是中间的“字节码”,然后由一个运行时系统(即Java虚拟机)解释

Strictly speaking, Perl also uses an intermediate byte code, but the separation of the phases is mostly invisible.严格来说,Perl 也使用了一个中间字节码,但是阶段的分离大多是不可见的。

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

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