开发者

Version handling of Perl in Windows

开发者 https://www.devze.com 2023-01-26 06:45 出处:网络
Is possible to use different vers开发者_JAVA技巧ion of Perl without using the SETor manipulating the environment variable \"PATH\"

Is possible to use different vers开发者_JAVA技巧ion of Perl without using the SET or manipulating the environment variable "PATH"

I need a mechanism that allows me to work with different version of Perl for different script without affecting the system configuration. (e.g. I am using Perl ver 5.6.1 for some scripts and perl 5.8.8 for other Perl scripts)


It's an old trick I do when I have two different, but very incompatible versions of Perl I have to use: Use different suffixes:

For example, I have ClearQuest on my system and must use cqperl (which is ClearQuest's version of Perl) to execute scripts that manipulate the issues in ClearQuest. Yet, if I have to manipulate SQL data from our database, I have to use my ActivePerl because I can't add in the DBI module into cqperl.

What I did was associate the *.pl suffix with ActivePerl and the *.cqpl suffix with cqperl. Now, when I execute a script, and it ends in *.cqpl, it uses one version of Perl while a script that ends with *.pl is executed by another version of Perl.

To associate a suffix with a program, go into a Windows Explorer window and select Folder Options from the Tools menu. Then, click on the File Types tab. Click on the New button and create a new extention to associate with the file. Then, select it in the Registered File Types window, and click on the Advanced button on the bottom.

Create an Open action, and associate it with the full path name of the Perl you want to execute that suffix. Like this:

"C:\Perl\bin\perl.exe" "%1" %*

The %* is important, so you can pass other parameters to your program.

In your case, you could use *.pl for Perl 5.8.8 and *.pl6 for Perl 5.6.

You don't even need to put Perl's bin directory in your path. Just type the name of your script and that's it.


On Unix: use shebang line.

On Windows: when perl is installed, it usually created two executables: perl.exe and perl5.N.M.exe. For ex. in my Strawberry installation I have perl.exe and perl5.10.1.exe. So if both perls are in PATH, you can call them as perl5.6.1 and 5.8.8. I.e "perl5.6.1 program.pl".

P.S. I'd suggest to upgrade whole environment to 5.12.2 - Perl has many new useful features.


you can always just run your scripts using the perl interpreter of your choice, let's suppose you have 2 different perls installed in с:/perl_56 and c:/perl_58.

in CMD.exe you can try this:
c:/perl_56/bin/perl.exe path_to_your_script here
and
c:/perl_58/bin/perl.exe path_to_your_script here

to run scripts through different versions of perl. unfortunately, you can't use the "shebang" in the beginning of your scripts in windows as you could do on unix systems.

0

精彩评论

暂无评论...
验证码 换一张
取 消