[tpm] Is there a way to choose from several interpreters, using the hashBang?

Stuart Watt stuart at morungos.com
Fri Jun 24 12:03:42 PDT 2011


On 11-06-24 02:32 PM, J Z Tam wrote:

> CAVEAT:  Windoze XP and Server2003/5  here. Ugh.  I'm trying to figure 
> out an elegant way to have multiple install trees able to be sourced, 
> either just before a perl program is executed, or at the time the 
> hashBang line is encountered.
>
> I thought there was a nifty cool way to select the particular   perl 
> interpreter just before the #! line, or actually AT the  #!  line.
> 1. Q: what if the caller's %PATH% environment variable does NOT 
> contain a valid pathToInterpreter
> 2. Q:  What if the the install tree that is eventually found, is 
> missing a use'd or require'd  package, or the wrong version of the 
> package?

I believe hashbang is only UNIX-ish systems. In fact, it isn't exactly 
reliable even there, and I tend to use #!/usr/bin/env perl to find the 
one in the path, just to be on the safe side. And on Windows, the path 
is really what you need to use. I think you can map the file extension 
to the executable, that would be the Windowsy thing to do. But I always 
work to keep the dependency on the executable out of the scripts to 
reduce maintenance. Scripts will, therefore, fail if there isn't a Perl 
in the path, and throw errors in the event of a missing module or file, etc.

Windows does also use some environment variables, such as PERL5LIB, 
which is used to initialize @INC, in addition to the contents of the 
command line.

So on Windows, it usually comes down to environment variable hacking of 
some sort. Usually I did this by autogenerating batch scripts which 
contain the right values (I have other values to set), but most people 
use pl2bat for this. In fact, pl2bat might be what you are looking for. 
It's probably there already installed.

All the best
Stuart


More information about the toronto-pm mailing list