What should I use for a Perl script's shebang line?

后端 未结 8 1856
北荒
北荒 2020-12-02 22:19

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         


        
8条回答
  •  醉酒成梦
    2020-12-02 22:41

    This is one of the things which I dislike about Perl.

    On Windows, if you are using ActiveState Perl at least, if the file ends with .pl then the Windows registry will run the Perl interpreter for you, regardless of the shebang line. On Cygwin, I am not sure why but #! perl works too. On Unix you should put the full path to your Perl executable in the shebang line. Schwern's idea of using env is convenient, but has some danger, as I pointed out in a comment.

    This is why I suggest to you that the best solution is to package your Perl scripts as CPAN modules. CPAN installers like Module::Build will then change the shebang line to the full path to your Perl interpreter. (I am not sure whether Schwern's installer, ExtUtils::MakeMaker, does this or uses env, since I don't use it.)

提交回复
热议问题