in reply to How to tell what version of Perl a script needs?

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

Replies are listed 'Best First'.
Re^2: How to tell what version of Perl a script needs?
by cog (Parson) on Apr 19, 2005 at 17:32 UTC
    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.
Re^2: How to tell what version of Perl a script needs?
by Whitehawke (Pilgrim) on Apr 19, 2005 at 18:43 UTC

    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.

        Heh. A few months ago, I convinced them that a development server was a good thing to own; I'm still trying to convince them that they should actually use it. For the most part, they are still doing development and testing on the production machines. They have even gone so far as to tell me that the dev machine is "for my use", implying that there are no plans to have anyone else use it.

        I've recently raised the issue of putting all the templates in a centralized database. There are some legal reasons why this might be sticky, but I'm going to see if there isn't a way around them. In the meantime, they are very reluctant to change their Perl versions, since it often breaks the existing code when they upgrade.

        Those tell me how to determine the version of perl ($^V) and how to enforce that that version be no lower than a particular release (require/use). They do not do what I am asking for. Thank you for the suggestion, though.