markcsmith has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I would like to write scripts that are more portable across different machines w/ different locations for the perl interpreter. Can I replace the line:

#!/usr/bin/perl

with something that will find the interpreter, then evaluate that location so as to invoke it? Thanks!


mark

Replies are listed 'Best First'.
Re: portable interpreter invocation
by perrin (Chancellor) on Mar 11, 2003 at 20:30 UTC
      Except that it sometimes, very rarely, is /usr/local/bin/env or /bin/env.. and then you have the same problem all over, except with env..

      Makeshifts last the longest.

Re: portable interpreter invocation
by dws (Chancellor) on Mar 11, 2003 at 20:23 UTC
    I would like to write scripts that are more portable across different machines w/ different locations for the perl interpreter.

    The standard approach for this is to provide an install script that locates Perl and modifies the #! lines on your components to point to wherever Perl is on that particular platform.

Re: portable interpreter invocation
by bronto (Priest) on Mar 12, 2003 at 10:25 UTC

    Directly from the Camel book, 3rd edition, page 488:

    #!/bin/sh -- -*- perl -*- -p eval 'exec perl -S $0 ${1+"$@"}' if 0 ;

    That is: run a (shell) eval and let the shell execute perl wherever it is in your $PATH

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz
Re: portable interpreter invocation
by IlyaM (Parson) on Mar 11, 2003 at 23:53 UTC