Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
I have this desire to check some code into our version control system that can just run as-is. However, the version of perl that it needs to use is pre-determined by the level of perl that we're currently shipping (which is, apparently, 5.8.8, despite my pleas to move up to 5.10.1, which was current at the time I made the request). Since our test machines can vary, /usr/bin/perl, which is definitely the right level on the test boxes (tightly controlled) may not be the right level on some development boxes, such as mine (since Gentoo just upgraded from 5.8.8 to 5.12.2 over the weekend).
So I've been trying to compose in my head a way to check in a perl script, in my case it's a wrapper around App::Prove, such that you can just "do something" once, and that script will always use the correct perl, while the same file, unchanged, will use perl in potentially a different location on another machine.
I figured others may have run across the same thing, and may have alternate (better) suggestions. The best I've come up with thus far is to replace the #!/usr/bin/perl line at the top of my script with:
Then, once I add the execute bit, running the tool should work. If I "export DEV_PERL=perl5.8.8" prior to running it, then my locally built (*) 5.8.8 will run it, but on boxes where /usr/bin/perl already is 5.8.8, then they'll continue just fine. Of course, to this I'd want to check that the correct perl is being loaded, so something like this:# -*-perl-*- eval 'exec ${DEV_PERL:-/usr/bin/perl} -S $0 "$@"' if 0;
though it may not need to be in a BEGIN. I'm thinking of BEGIN just because I don't want all the other use's executed since they may fail anyway.BEGIN { if ($] != 5.008008) { die sprintf "Must use perl 5.8.8, this is %vd!\nTry setting DE +V_PERL to point to the right version.\n", $^V; } }
Of course, then the next fun bit is refactoring - when we upgrade the perl on the production machines, we'll want to start using the upgraded perl on the tests, too, so then I'd have to update all the scripts to check the new level. Maybe put it in a module that all scripts must use first, I suppose, so I don't have to repeat myself.
Has anyone else looked into this type of issue before? If so, how did you address it (and if you'd change that, how)? If not, how would you?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamic $^X
by ig (Vicar) on Oct 26, 2010 at 09:03 UTC | |
by Argel (Prior) on Oct 27, 2010 at 16:41 UTC | |
|
Re: Dynamic $^X
by ambrus (Abbot) on Oct 26, 2010 at 13:43 UTC | |
|
Re: Dynamic $^X
by tospo (Hermit) on Oct 27, 2010 at 12:13 UTC | |
|
Re: Dynamic $^X
by andal (Hermit) on Oct 27, 2010 at 07:58 UTC |