Perl shebang for different versions

In a Perl script typically a shebang line is something like:

#!/usr/bin/perl


this works great if you want to use a wide, system based, Perl for your scripts. But what if you have several different installations of Perl and want to run the same script using different Perl versions without having to change the shebang line. Well, one possible and straightforward solution is to change it to something like:

#!/usr/bin/env perl


and then push the version you want to use to your $PATH environment variable. This can even be easily done based on the user. For example, you can have a user named 'perl_5.10' and for that user have:

PATH=/usr/local/perl_5.10/bin:$PATH


now, this user runs scripts (with the env version of the shebang line) using Perl 5.10.

5 Comments

Unless you have a CGI running under Apache. Then your shebang must be:

#!C:\PERL\BIN\PERL.EXE

Yeah, not using /usr/bin/env for perl, python, sh etc. is one of my biggest pet peeves about Unix programs.

Using a "wide" Perl should be discouraged! :-p

If you're going to put perl_5.10/bin first in your $PATH anyway, what difference does env make?

$PATH isn't used for absolute paths, i.e. this:

#!/usr/bin/perl

Always uses /usr/bin/perl regardless of your $PATH settings. These two are different however:

#!/usr/bin/env perl
#!perl

Leave a comment

About smash

user-pic I blog about Perl.