PAR :: Packer如何工作? [英] How does PAR::Packer work?

查看:74
本文介绍了PAR :: Packer如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PAR :: Packer,这个问题在我脑海中浮现. PAR :: Packer在Perl中如何工作?像g ++一样将Perl脚本实际上编译到.exe,还是将C ++源代码编译成.exe,还是像Python中的py2exe一样工作,它将解释器和脚本打包到.exe中?

I was using PAR::Packer and this question popped up in my mind. How does PAR::Packer work in Perl? Does it actually compile the Perl script to .exe like g++ compiles C++ Sources to .exe or does it work like py2exe in Python that packs the interpreter and the script into an .exe?

推荐答案

要明确地说:

  • PAR::Packer 之类的工具不会编译"您的Perl脚本.他们将perl解释器与您的源文件和所有必需的模块捆绑在一起,成为一个庞大的可执行文件.运行时,将提取原始源并将其输入到随附的perl中.

  • Tools like PAR::Packer do not "compile" your Perl script. They bundle the perl interpreter together with your source files and any required modules into a big fat executable file. When it is run, the original sources are extracted and fed to the enclosed perl.

这可以很好地工作,但是并不能提高速度(相反……). only 的优点是您可以将程序作为单个文件(尽管很大)分发,而没有依赖项.

This works reasonably well, but does not yield a speed improvement (on the contrary…). The only advantage is that you can distribute your programs as a single (albeit quite large) file, without dependencies.

有一个名为perlcc的实验性工具,它可以将某些Perl程序转换为C或Perl字节码序列化.正如文档所述:

There is a very experimental tool called perlcc that is able to translate some Perl programs to C or a Perl bytecode serialization. As the docs put it:

不能保证以此方式生成的代码正常工作.整个codegen套件(包括perlcc)应被视为非常是实验性的.强烈建议不要将其用于生产目的.

The code generated in this way is not guaranteed to work. The whole codegen suite (perlcc included) should be considered very experimental. Use for production purposes is strongly discouraged.

这是因为Perl语言不支持静态编译.它需要能够在解析过程中执行代码,以便在执行主要执行阶段的同一会话中对某些动态功能进行执行.

This is because the Perl language does not support static compilation. It needs to be able to execute code during parsing for some dynamic features during the same session where the main execution phase takes place.

还有其他一些商业工具,通常与PAR :: Packer(创建胖可执行文件)属于同一类别.

There are other, commercial tools, that usually fall in the same category as PAR::Packer (creating fat executables).

摘要:如果要单个可执行文件,请使用PAR :: Packer.如果需要速度,请内联一些C(或使用XS).没有工具可以将所有Perl脚本编译为机器代码.

Summary: If you want a single executable, use PAR::Packer. If you want speed, inline some C (or use XS). There is no tool that can compile all Perl scripts to machine code.

这篇关于PAR :: Packer如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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