gpt4 book ai didi

linux - 如何在 perl 中为 windows 和 linux 组合 header

转载 作者:太空狗 更新时间:2023-10-29 11:44:37 26 4
gpt4 key购买 nike

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 并根据操作系统选择正确的 header ?

最佳答案

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

看起来您正在使用 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 方面,如果像 ./my-script.pl 中那样将脚本作为可执行文件运行,您也只需要 shebang,而不是像 perl 中那样手动指定解释器my-script.pl (或者,再次,如果你需要解释器标志)。在基于 Linux/UNIX 的系统上,shebang 的规范建议是 #!/usr/bin/env perl,以避免对解释器的硬编码路径的需要。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com