Neville hobson wrote:
: I'm writing perl scripts that will be distributed to locations where I
: cannot gaurantee the location of perl. Is there a clean alternative to the
: shebang with the specific perl path? Maybe using an environment variable to
: locate perl?

OK, here's one solution, extracted from the earlier one I wrote about
packaging the script in a module. It's a short script your users can
run that will edit the shebang line and put the eval hack into the script
for you, with their local perl paths.

Suppose this script is called "fix" (note the lack of a shebang):

        use ExtUtils::MakeMaker;
        ExtUtils::MM_Unix->fixin(shift or die "usage: perl $0 filename\n");

and this script that you want to fix is called "myscript.pl":

        #!/usr/local/bin/perl
        print "foo!\n";

Then after running this command line on my system:

        % perl fix myscript.pl

myscript.pl will looks this:

        % more myscript.pl
        #!/faxafloi/data1/bin/perl

        eval 'exec /faxafloi/data1/bin/perl  -S $0 ${1+"$@"}'
            if 0; # not running under some shell
        print "foo!\n";

because the first "perl" in my path is /faxafloi/data1/bin/perl. In
other words, "fix" will replace the shebang line with the path of the
perl executable that was used to run "fix".

So you'd need to deliver this "fix" script to your users with
some simple installation instructions.

-- tdk

Reply via email to