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

Dear Monks,

I am terribly frustrated searching online for this so I thought I would put up a post.

I am running perl 5.8 on my lamp server (perl blah.perl runs this one) I also have 5.10 in my home directory and I would like to use it (lets say perl2 blah.perl) How can I do this?

Is there a good tutorial for this?

Replies are listed 'Best First'.
Re: 2 versions of perl
by rudder (Scribe) on Apr 12, 2008 at 06:09 UTC

    You could do one of the following:

    1. Use a shebang line at the beginning of your script to point to the perl you want: "#!/home/YOU/SOMEDIR/perl/bin/perl", or
    2. Edit your PATH to put /home/YOU/SOMEDIR/perl/bin ahead of wherever the system perl is, then use a shebang like "#!/usr/bin/env perl", or
    3. Run the script directly using your own perl: /home/YOU/SOMEDIR/perl/bin/perl foo.pl

    For SOMEDIR, I usually use opt.

    Edit: Note, I have a symlink in ~/opt/perl pointing to ~/opt/perl-5.10.0.

    Note that this isn't really a Perl question per se, but rather just a question about how to tell your shell to find the perl you want it to find.

    Edit: Whoops. Re-reading your question more carefully, looks like nefigah's tip is more like what you want. In that case, you're probably looking at doing:

    cd ~/bin
    ln -s ../SOMEDIR/perl-5.10.0/bin/perl perl5.10
    

    This assumes you have your own ~/bin somewhere in your PATH.

Re: 2 versions of perl
by Khen1950fx (Canon) on Apr 12, 2008 at 06:16 UTC
    I use 5.8 most of the time. Sometimes, I need to use 5.10.0, which I have in /opt/extras. To use 5.10.0, I normally do this:

    /opt/extras/bin/perl5.10.0 script.pl

    Or, for example, if I want to use CPAN to download pmtools:

    /opt/extras/bin/cpan Devel::Loaded

    Next, for example, I want to go back to 5.8 to check the path of Devel::Loaded:

    pmpath Devel::Loaded

    To check the path of Devel::Loaded in 5.10.0:

    /opt/extras/bin/perl5.10.0 -S pmpath Devel::Loaded

    Just a few ways of doing it. I hope it helps.

Re: 2 versions of perl
by nefigah (Monk) on Apr 12, 2008 at 06:13 UTC

    You can also make a symbolic link to your 2nd perl in your path.

    sudo ln -s /home/path/to/perl510 /usr/local/bin/perl510

    Then you really can just say perl510 blah.pl


    I'm a peripheral visionary... I can see into the future, but just way off to the side.

Re: 2 versions of perl
by marc_ (Deacon) on Apr 12, 2008 at 10:16 UTC
    In bash: alias perl-10='/path/to/perl-5.10/bin/perl'
    In t/csh: alias perl-10 /path/to/perl-5.10/bin/perl'

      That would be fine if you were trying to invoke Perl from the commandline; it won't work for a script.

      ben@Tyr:~$ alias foobar="/usr/bin/perl" ben@Tyr:~$ cat <<! >xyz > #!foobar -w > print \$ARGV[0] > ! ben@Tyr:~$ chmod +x xyz ben@Tyr:~$ ./xyz Hello -bash: ./xyz: foobar: bad interpreter: No such file or directory
      
      

      Update: Added a '\' in front '$ARGV'. It doesn't change the outcome, but it actually puts "$ARGV[0]" instead of "[0]" into 'xyz'...

      -- Human history becomes more and more a race between education and catastrophe. -- HG Wells