我应该为 Perl 脚本的 shebang 行使用什么? [英] What should I use for a Perl script's shebang line?

查看:29
本文介绍了我应该为 Perl 脚本的 shebang 行使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 Perl 脚本的 shebang 行使用这些中的哪一个更好或更快?

Which of these is better or faster to use as the shebang line for a Perl script?

#! perl

#! perl.exe

#! fullpath/perl(/perl.exe)

#! partialpath/perl(/perl.exe)

而且,当使用 #!perl 时,当它在特定系统上工作时,我如何在脚本中找出我正在使用的 perl 解释器,以便我可以将它放入 shebang线?

And, when using #!perl, when it works on a particular system, how do I find out in the script which perl interpreter I'm using so I can put that one into the shebang line?

而且,如果使用 /path/path/perl,是否允许将 *... 用于文件夹?

And, if using a /path/path/perl, are * or ... allowed to be used for the folders?

推荐答案

如果您必须硬编码 #!,请使用 #!/usr/bin/env perl.为什么?您想要的是 Perl 程序与用户首选的 Perl 一起运行.这将是他们 PATH 中的第一个.#!perl 不符合我的意思,它不会搜索用户的 PATH,#!/usr/bin/env perl 是你实现它的方式./usr/bin/env 在 Unix 系统上将始终存在.

If you have to hard code #!, use #!/usr/bin/env perl. Why? What you want is for the Perl program to run with the user's preferred Perl. That's going to be the first on in their PATH. #!perl doesn't do what I mean, it doesn't search the user's PATH, #!/usr/bin/env perl is how you pull that off. /usr/bin/env will always be there on Unix systems.

如果用户使用的是 Windows,正如其他人指出的那样,这无关紧要.Windows 不使用 #!它使用文件扩展名关联.确保您的程序名为 foo.pl 或其他名称,它会起作用.但包括#!无论如何,因为一些实用程序和编辑器会使用它.

If the user is using Windows, as others have pointed out, it doesn't matter. Windows doesn't use #! it uses file extension associations. Make sure your program is called foo.pl or something and it'll work. But include the #! line anyway as some utilities and editors make use of it.

如果您要发送代码,请让安装人员处理.MakeMaker/Makefile.PLModule::Build/Build.PL 都会改变你的 #!行以匹配用户用于安装的 perl.他们会为您解决这个问题.

If you're shipping code, let the installer take care of it. Both MakeMaker/Makefile.PL and Module::Build/Build.PL will change your #! line to match the perl the user used to install with. They will take care of this problem for you.

如果您要为自己的生产使用安装代码,则应使用特定 perl 副本的完整路径.哪个perl副本?一种特定于您的项目.这是否意味着您需要为每个项目编译 perl?不,您可以制作符号链接.项目 foo 可能有 /usr/local/bin/fooperl 指向 /usr/bin/perl5.18.使用 #!/usr/local/bin/fooperl.现在,如果您决定升级 perl,您可以通过更改符号链接来为每个项目进行升级.

If you are installing code for your own production use, you should use the full path to a particular copy of perl. Which copy of perl? One specific to your project. Does this mean you need to compile perl for every project? No, you can make a symlink. Project foo might have /usr/local/bin/fooperl point at /usr/bin/perl5.18. Use #!/usr/local/bin/fooperl. Now if you decide to upgrade perl you can do it per project by changing the symlink.

这篇关于我应该为 Perl 脚本的 shebang 行使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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