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:

# -*-perl-*- eval 'exec ${DEV_PERL:-/usr/bin/perl} -S $0 "$@"' if 0;
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:
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; } }
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.

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!


In reply to Dynamic $^X by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.