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

Can I have multiple versions of Perl running on the same box as long as I have differentiate using the shebang line? I want to do this so I can use new functionality while I work to verify older scripts work alright with the newer version.

Replies are listed 'Best First'.
Re: Multiple Versions of Perl
by kvale (Monsignor) on Sep 07, 2004 at 17:23 UTC
    Sure, no problem. I often build the latest experimental perls in my home directory, leaving the origianl perl untouched in the /usr directory (Mandrake 9.1).

    To do this, simply build perl with the usual Configure process and when asked where you want to install, specify your desired directory.

    -Mark

Re: Multiple Versions of Perl
by eLore (Hermit) on Sep 07, 2004 at 17:52 UTC
    Yes you can. Another important consideration that modules installed in one "environment" will not exist in the other.

    I've done something similar to house multiple development and testing environments on the same server.

    UPDATE: Limbic~Region was kind enough to point out that it may exist in both environements if you set @INC to include your "development" include directory.

    Taking his idea one step further (I think he was hinting at this in his message to me): set @INC to reference a local environment variable that points to your "current" directory structure of includes. That way, you set an environment variable before execution, and never have to change the actual script as you migrate from env to env. The one major drawback to this approach that I can see is security. If someone can change the environment variable, they could overload the @INC to include potentially malicious modules.

    Thoughts? Rebuttal?

      eLore,
      I should have taken the time to respond properly but I had a meeting to go to and just /msg'd you. My point was that there is nothing preventing two different installations/versions/configurations of Perl from having one or more of the same @INC paths. This may or may not be a good thing. Compatability usually comes into question at some point. You can modify @INC in several ways -
      • Compile time option
      • PERL5LIB environment variable
      • use lib pragma
      Chances are you wouldn't unintentionally cross paths and if you did do so intentionally it is because you know what you are doing. For those who get strange error messages with multiple versions - this might be something to look at. I have personally had problems with a Cygwin installation and ActiveState.

      Cheers - L~R

Re: Multiple Versions of Perl
by sintadil (Pilgrim) on Sep 07, 2004 at 18:49 UTC

    Make sure that you also specify the proper prefix when installing modules, or you'll get EACCES (permission denied) when you try to install the files. A good way to ensure that you can't install files in your vendor's Perl directory is to install the other Perl's modules as a user who doesn't have write permissions to the vendor's Perl directory. I do this on my machine, and it works quite well.

    Also, don't be an idiot like yours truly and forget to set PERL5LIB before installing modules with CPAN / CPANPLUS. If you do, you lock yourself into an infinite loop because the shell will repeatedly install modules but it won't be able to see them. :)

Re: Multiple Versions of Perl
by ysth (Canon) on Sep 07, 2004 at 17:53 UTC
    I find the easiest way to do this is to configure with -Dversiononly. This makes all installed files versioned (e.g. perl5.8.5, perldoc5.8.5, etc.).
Re: Multiple Versions of Perl
by QM (Parson) on Sep 07, 2004 at 18:45 UTC
    I would instead suggest using path and environment variables to differentiate. Then when you test and "release" your script, you don't need to edit it.

    I used an alias to update my path and environment variables quickly, so I could switch between the versions I had available. [You might find Perl useful for this as well -- simply pushing a new directory on the front of the path can make it grow very quickly.]

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Re: Multiple Versions of Perl
by PerlingTheUK (Hermit) on Sep 07, 2004 at 18:07 UTC
    You surely can, I use windows and install the different AS Versions in different folders and then set the variables accordingly.
    Due to some errors in AS Perl 5.8.4 I wonder if you can actually change the compiler version within the script telling to load one snippet of code with Version 5.8.3 and another when using 5.8.4.

    Cheers,
    PerlingTheUK