linux - 如何在 Windows 和 Linux 的 Perl 中组合 header

标签 linux perl

My development environment is windows and hosting environment is Linux. At the time of development i have the header:

"#!c:/perl64/bin/perl.exe"

在 Web 服务器上托管时,我需要将所有 Perl 文件中的 header 更改为:

"#!/usr/bin/perl"

如果我错过了什么,这个过程很容易出错。是否可以组合 Perl 文件中的两个 header 并取决于操作系统,它会选择正确的一个?

最佳答案

简短回答:您不需要在 Windows 上使用 ActivePerl 进行 shebang。

看起来您正在使用 ActiveState Perl(默认情况下为 C:\perl64,Strawberry 使用 C:\strawberry )。尽管它们历史上是 UNIX-y 的东西,ActiveState 解析 Perl 文件中的 shebang 行,但只是为了获取解释器标志(如 -T 用于污点检查),但您没有使用任何解释器标志,因此您不需要Windows 上的 shebang。

如果您的脚本在没有 shebang 的情况下在 Windows 上“无法执行”(具体错误在这里会有所帮助),则说明有其他问题。确保您的脚本具有 .pl 扩展名,并且确保您的 ActivePerl 安装已设置为 .pl 文件的默认安装。以下是安装注意事项:

http://docs.activestate.com/activeperl/5.18/install.html

此外,根据上述文档:

On Windows 2000/XP/2003/Vista systems ActivePerl installations must be performed by a privileged user only. If you install ActivePerl without full administrator privileges, the following problems occur: ... PerlScript file associations are not created

在 Linux 端,如果将脚本作为可执行文件运行,您也只需要 shebang,如 ./my-script.pl 中所示。 ,而不是像perl my-script.pl那样手动指定解释器。 (或者,如果您需要解释器标志)。在基于 Linux/UNIX 的系统上,shebang 的规范建议是 #!/usr/bin/env perl ,以避免对解释器的硬编码路径的需要。

关于linux - 如何在 Windows 和 Linux 的 Perl 中组合 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837268/

相关文章:

linux - struct load_info 中的字段strmap 是什么意思?

linux - 文件路径名称存在问题,可能存在损坏的字符

perl - 如何在特定时间运行脚本,比如每个星期六?

linux - 使用 wget 下载 html 页面中的嵌入链接

linux - JAI 图像 I/O 的 Posix 变量

perl - 如何在 perl 中使用 typeglob 做与引用相同的事情?

regex - 如何检查 Perl 字符串是否包含字母?

string - 使用 PERL 脚本精确匹配和替换文件

linux - git 在提交 linux 时使用 root 而不是我的用户名

c - 以编程方式访问shell扩展,替换和单词拆分