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

查看:85
本文介绍了我应该在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天全站免登陆