How can I control the Perl version used when submitting grid jobs?

蓝咒 提交于 2019-12-03 16:10:18
draegtun

I don't recommend putting the perlbrew switch perl-5.12.2 in any script you run. Its really only for command line usage.

If you need a script to use a specific version of Perl then either give it the full perlbrew path on the shebang:

#!/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl

use 5.012;
use warnings;
...

Then make sure its executable and run like so:

chmod +x your_perl_program.pl
./your_perl_program.pl

Or alternatively use the full pathname to the perl binary in your script:

#!/bin/bash

/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl your_perl_program.pl


BTW, you will have potential production and security issues if you run anything unqualified in your scripts or perl programs. For eg:

#!/bin/sh

# security risk
perl some_script.pl

# and not just perl
tar cvf archive.tar *.txt

# production risk
/home/dave/perl5/perlbrew/bin/perl some_other_script.pl

The first two are bad because it will pick up the first perl & tar it finds in your path. So this depends on $PATH setting and this could become a security risk. The last is also not good because its reliant on what perl perlbrew is currently switched to at the point in time its run :(

So doing this can be a potential production & security nightmare. Instead the above should be written like this:

#!/bin/sh

# fully qualified now.  Uses OS provided perl
/usr/bin/perl some_script.pl

# ditto
/usr/bin/tar cvf archive.tar *.txt

# this needs to run in perl 5.12.2
/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl some_other_script.pl

Hope that all makes sense?

I'd recommend against using perlbrew. It doesn't really give you that much value and it just causes confusion about what perl you are using. perlbrew really assumes that everything running at the same time agrees on which perl they should use. I think that's just a recipe for headaches as different programs start switching perls out from under you, perhaps before you get the chance even to use the perl you think you switched to.

Just install the perls that you want and call the one that you want.

 $ perl5.12.2 /home/dave/scripts/proc_12.pl ...

For instance, to install a perl you just run from the source tree (with whichever prefix you want):

 $ ./Configure -des -Dprefix=/usr/local/perls/perl-5.12.2
 $ make install

I then make symlinks to all my installed perls with my make_links script. When I want to use Perl 5.12.2, I just use ~/bin/perl5.12.2. I never have to switch perls. When I want to install a Perl module, I use the cpan for it:

 cpan5.12.2 Some::Module

I've never unsure about what version I'm using, and there's no race condition in moving symlinks around.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!