更新时间:2023-09-08 20:08:04
只是为了扩展这里的其他一些列表,这些是一些在 Python 中可能非常笨拙的 Perl 构造(如果可能的话).
Just to expand on some of the other lists here, these are a few Perl constructs that are probably very clumsy in python (if possible).
local
关键字)mysub() = 5;
类型代码)wantarray
进行检查)eval
local
keyword)mysub() = 5;
type code)wantarray
)eval
这个列表还在继续,有人可能会尝试在所有类似的结构之间创建映射,但最终会因为一个简单的原因而失败.
The list goes on an on, and someone could try to create a mapping between all of the analogous constructs, but in the end it will be a failure for one simple reason.
Perl 不能静态解析.Perl 代码中的定义(尤其是 BEGIN 块中的定义)改变了编译器解释剩余代码的方式.因此,对于非平凡的程序,从 Perl => Python 转换会遇到停机问题.
Perl can not be statically parsed. The definitions in Perl code (particularly those in BEGIN blocks) change the way the compiler is going to interpret the remaining code. So for non-trivial programs, conversion from Perl => Python suffers from the halting problem.
在程序运行完成之前无法确切知道所有程序将如何编译,理论上可以创建一个每次运行时编译方式不同的 Perl 程序.这意味着一个 Perl 程序可以映射到无数个 Python 程序,其中正确的只有在 perl 解释器中运行原始程序后才能知道.
There is no way to know exactly how all of the program will be compiled until the program has finished running, and it is theoretically possible to create a Perl program that will compile differently every time it is run. Meaning that one Perl program could map to an infinite number of Python programs, the correct of which is only know after running the original program in the perl interpreter.