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. | [reply] |
|
|
| [reply] |
|
|
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.
| [reply] |
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".
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] |
|
|
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.
| [reply] |
|
|
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.
| [reply] |
|
|
Simple. Learn from the Java world: just distribute whatever version of Perl you need with your application.
Problem solved.
| [reply] |
|
|
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.
| [reply] |
|
|
|
|
|
|
| [reply] |
|
|
|
|
|
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. | [reply] |
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? | [reply] |
|
|
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). | [reply] [d/l] [select] |
|
|
# 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
| [reply] [d/l] |