Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Using Multiple Versions of ActivePerl, or I Want to Use ActivePerl 5.8.0 But Not Break My ActivePerl 5.6.0

by ibanix (Hermit)
on Dec 02, 2002 at 04:39 UTC ( #216842=perlmeditation: print w/replies, xml ) Need Help??

Introduction

This is a short writeup on using two (or more!) ActivePerl distributions at the same time.
I didn't find a node on this topic so I am writing this to the best of my knoweldge.
Feedback and/or corrections are welcomed. Thanks to the CB folks for helping with this!

Note: Where I say "Perl 5.8.0" you can insert any ActivePerl version.

Why?

* You want to use Perl 5.8's new features.
* You want to test compatability of your scripts with 5.8.
* You have multiple ActivePerl distributions in production and you need to check compatability against all of them.
* Do you really need another reason? ;-)

Installing 5.8.0

#1: Download the ActivePerl 5.8.0 distribution. Note that this is still considered Beta!
The MSI installer is prefered, as it will easily install/deinstall.

#2: Run the installer. Be sure to change the install path to a location other than your current Perl install path!
Your current install path can be found from a comand line with perl -V.

On my systems I have ActivePerl 5.6 at C:\perl-5.6.0 and ActivePerl 5.8.0 at C:\perl-5.8.0. Pretty obvious, really.

When you reach the dialogue box asking you if you add the Perl binary to %PATH%, do not do so. De-select all of the options, unless you want to use Perl 5.8.0 by default. The IIS and ISAPI options will also override the current settings, so don't select them unless you want 5.8.0 to be used by default. Finish the installation.

#3: Now you should have ActivePerl 5.8.0 installed. Confirm you can use by running C:\perl-5.8.0\bin\perl.exe -V and you should get
Summary of my perl5 (revision 5 version 8 subversion 0) configuration: ... Locally applied patches: ActivePerl Build 802 Built under MSWin32 Compiled at Nov 8 2002 00:54:02 @INC: C:/Perl-5.8.0/lib C:/Perl-5.8.0/site/lib .

Making Scripts Use the Perl You Want

Windows, in typical fashion, does not support shebang (#!) options in scripts, so we will not be able to put #!C:\perl-5.8.0\bin\perl.exe at the top of our scripts. Pity. However, there are a few workarounds:

Workaround #1: Batchfiles

Create a batchfile (.bat) that calls your script with the desired perl binary, eg. C:\perl-5.8.0\bin\perl.exe myscript.pl. Then run the batchfile.

Workaround #2: File Extensions

Using the ftype and assoc commands, you can set what file extensions call which binaries.
Note: This works on Windows 2000, and I assume it works on Windows NT and Windows XP. No idea if it works on any other versions.

First, setup a filetype like so: ftype perl_58_script="C:\perl-5.8.0\bin\perl.exe" "%1" %*,
then associate it with a file extension: assoc .p58=perl_58_script.

That's it! foo.p58 should now use perl 5.8.0

You can confirm that your script is using the perl version you want by testing the $^V variable. See perlvar. In general, this should work:
if ($^V eq v5.6.1) { print "I found version 5.6.1!\n"; } if ($^V eq v5.8.0) { print "I found version 5.8.0!\n"; }
Release notes and such should be in C:\Perl-5.8.0\html\index.html once you've installed.

Dealing With Modules

Perl 5.8.0 is binary incompatible with earlier perl versions, so XS modules will need re-compilation. In addition, if you need a module for perl 5.8.0, you will need to redefine @INC to include your previous module dirs (which one hopes are compatible). This is probally dangerous.

The better but tedious option is to install the modules for perl 5.8.0 seperately. The Perl Package Manager is the default way of doing this with ActivePerl. To call the PPM for 5.8.0, specify the full path to it: C:\perl-5.8.0\bin\ppm. Note that 5.8.0 uses PPM 3; if you like PPM 2 better, use C:\perl-5.8.0\bin\ppm2

Nodes I Stole Stuff From

Notes on Upgrading to 5.8.0 on a production web server

Happy Win32 Perl-ing!

Update: Fixed "%l" to be "%1".
Note that the method of using ftype and assoc can also be found on page 5 of Dave Roth's excellent book,
Win32 Perl Scripting: The Administrator's Handbook
  • Comment on Using Multiple Versions of ActivePerl, or I Want to Use ActivePerl 5.8.0 But Not Break My ActivePerl 5.6.0
  • Select or Download Code

Replies are listed 'Best First'.
Re: Using Multiple Versions of ActivePerl
by jmcnamara (Monsignor) on Dec 02, 2002 at 09:58 UTC

    I also use several versions of ActivePerl for testing purposes.

    They are in installed in directories like this, where the \d\d\d is the ActivePerl version number:

    C:\Perl522 C:\Perl633 C:\Perl802

    The default version that I test with is ActivePerl 522 (5.005_03 ). To change between versions I do something like this:     SET PATH=C:\PERL802\BIN;"%PATH%"

    --
    John.

      I've done that as well, but if you keep reuse the same shell for a while, switching backwards and forwards, you can run reach the limit of what the shell will allow. And if you compile perl yourself, the paths can be quite long with the default options. I've set up a couple of batch files to call whatever perl I want:

      :: perl580.bat @echo off d:\dev\perl\5.8.0\bin\MSWin32-x86-multi-thread\perl5.8.0 %*
      > perl561 foo.pl # runs perl5.6.1 > perl580 foo.pl # runs perl5.8.0

      I have similar batch files set up for perldoc et al.

      -- simonflk

Re: Using Multiple Versions of ActivePerl, or I Want to Use ActivePerl 5.8.0 But Not Break My ActivePerl 5.6.0
by theorbtwo (Prior) on Dec 02, 2002 at 04:49 UTC

    I assume that will work on XP; ftype and assoc are still there, and from their /? help, I assume they still work the same way. (Interestingly, the help for ftype shows an example with perl). It will /not/, however, work on 9x/ME, which does not have ftype/assoc.

    However, you can do that step via Windows Explorer's Tools/File Options, on the File Types tab. (This is with IE6; it tends to move around.)


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Re: Using Multiple Versions of ActivePerl, or I Want to Use ActivePerl 5.8.0 But Not Break My ActivePerl 5.6.0
by grantm (Parson) on Dec 03, 2002 at 21:23 UTC
    Create a batchfile (.bat) that calls your script with the desired perl binary, eg.
    C:\perl-5.8.0\bin\perl.exe myscript.pl.

    You're probably already aware of this, but ActivePerl comes with a script called pl2bat which takes a perl script (*.pl) and creates a batch file (*.bat). The resulting file contains all your original source code along with a funky header that allows the script to be interpreted by both the Windows command shell and Perl.

    One advantage of this system is that it ensures the command line arguments you provide to the batch file get passed to the Perl script.

    You might need to edit the header code to make it explicitly call the version of Perl you want - I seem to recall it relies on the PATH environment variable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://216842]
Approved by jarich
Front-paged by IlyaM
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2023-01-28 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?