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

Oh Wisest and Wiliest:

Is there a way to say "tell me what the minimum version of Perl is that will run this script", for an arbitrary script?

  • Comment on How to tell what version of Perl a script needs?

Replies are listed 'Best First'.
Re: How to tell what version of Perl a script needs?
by adamk (Chaplain) on Apr 20, 2005 at 00:34 UTC
    You probably want Perl::MinimumVersion, based on a feature-use analysis with PPI.

    It doesn't exist yet, but should shortly. Watch this space (and the CPAN upload list).

    Anyone who wants to help out, message me and I'll add you to the Parse::Perl SourceForge project.
      Wow. I always knew that Perlmonks was the "ask and ye shall receive site", but this is just astounding. Thank you; that's exactly what I was looking for.
Re: How to tell what version of Perl a script needs?
by tlm (Prior) on Apr 19, 2005 at 17:29 UTC

    When it matters, a "well-written script" would have a line such as

    require 5.004;
    or
    use 5.004;
    and likewise for modules
    use Foobar 1.23 'baz';
    ...though I admit that this is one of those rules that are "observed in the breach".

    the lowliest monk

      And that line doesn't say "I only work with version X of above", it says "I refuse myself to work with anything less than version X".

      You see lots and lots of people starting scripts/modules with require 5.006 (or other) without even knowing what they're going to use.

        Surely a lot of the blame for that lies with h2xs, which casually inserts the current version of perl at the top of any created .pm files. Although admittedly the final responsibility for changing this lies with the author, I think too many people (myself included? never!) just think "isn't everyone running perl 5.020?", and leave it the way it is - any dependencies obviously work with that version, and to figure out the absolute minimum is Just Too Much Work.

      This is exactly why I have this question, actually.

      I'm working at a company where (IMO) the versions cannot be relied upon to be consistent or up to date (*) and the company wants to be able to copy scripts around from machine to machine. I've just finished writing a (fairly sizable) CGI for them and it suddenly occurred to me that, when they move it around, it might break if the provided perl is too low. I would like to be able to put in a 'use XYZ' line to at least document what version is required.

      (*) There are reasons for this and they aren't all bad. But that's a whole 'nother discussion.

        Simple. Learn from the Java world: just distribute whatever version of Perl you need with your application.

        Problem solved.

        What about having the same perl version everywhere? And possibly centralize all your scripts/modules in a development server, where things could be properly tested when upgrading the existing version.
Re: How to tell what version of Perl a script needs?
by PreferredUserName (Pilgrim) on Apr 19, 2005 at 17:22 UTC
    Don't forget that you need to vet not just the script, but also any modules the script uses (and modules that they use).

    Not the quickest way, but you could just pull and build old perls in a binary search fashion, and try your script with each one.

Re: How to tell what version of Perl a script needs?
by haoess (Curate) on Apr 19, 2005 at 17:35 UTC
    What do you mean with "run"? Compiling? Or printing/calculating the expecting result?
      I'll settle for compiling. Once it does that, I can take it the rest of the way. I've just never uploaded the CHANGELOGs into my brain, so I'm not sure precisely which version of perl is required in order to do (e.g.):
      for my $x (@x_indexes) {...}
      Which is a construct that I use all the time (the my declared inline with the for).

        You could install some major releases with different executables, and let them show you if they can compile your script:

        # just to get the idea ... $ ls /usr/local/bin/perl perl-5.004 perl-5.005 perl-5.006 perl-5.008 $ for i in /usr/local/bin/perl/* ; do "$i" -c yourscript.pl ; done