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/