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

Hi

I have a bunch (20+) of perl scripts that i use on both a development and production environment which have different perl paths. My question is this... is it possible to set the #! line using the environment? So something like this:

#!${DEV_PERL_PATH}

or am i barking up the wrong tree?

Thanks

Joe

-----

Eschew obfuscation, espouse elucidation!

Replies are listed 'Best First'.
Re: Setting #! path using environment
by moritz (Cardinal) on Jul 01, 2009 at 09:08 UTC
    You can use
    #!/usr/bin/env perl

    and manipulate your PATH environment variable so that the first perl found in PATH is the one you want your scripts to use.

Re: Setting #! path using environment
by JavaFan (Canon) on Jul 01, 2009 at 10:42 UTC
    You have to consider who is reading that line and acting upon it. The answer is: the kernel. And it's not emulating a shell or a program like perl. So it isn't looking for names of environment variables.

    So, you're barking up the wrong tree using this syntax. (But see the thread for alternative answers).

Re: Setting #! path using environment
by Anonymous Monk on Jul 01, 2009 at 10:33 UTC
Re: Setting #! path using environment
by afoken (Chancellor) on Jul 01, 2009 at 14:33 UTC

    Use a symlink to perl on the one machine to simulate the other machine, or create a new directory on both machines and place the symlink there, pointing to the proper perl binary. Use the symlink in the #! line.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Setting #! path using environment
by rovf (Priest) on Jul 01, 2009 at 11:47 UTC

    You could write a helper program, say dev_perl_exec in C or a similar language, which runs $ENV{DEV_PERL_PATH} and passes its stdin to this program, and use it as

    #!/.../dev_perl_exec
    So you basically would emulate the /bin/env trick, but not requiring that the "correct" Perl is in the PATH.

    -- 
    Ronald Fischer <ynnor@mm.st>
Re: Setting #! path using environment
by mzedeler (Pilgrim) on Jul 01, 2009 at 11:02 UTC

    If you're on linux or the like, the env command should be able to do the trick.