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

Is it possible to check in my script if Perl on my NT is version 5.6.1 and newer?
if ! ($perlVersion 5.6.1 and newer) { print "you do not have current version of perl"; exit; }

Replies are listed 'Best First'.
Re: Checking Perl version
by naChoZ (Curate) on Jul 08, 2003 at 13:00 UTC

      I would recommend using require 5.x over using $[. It is shorter, direct, and makes more sense when reading the code.

      Also, not to be pedantic, but I think a ; is needed:

      require 5.6.1;

      </ajdelore>

Re: Checking Perl version
by TVSET (Chaplain) on Jul 08, 2003 at 13:13 UTC
Re: Checking Perl version
by bigj (Monk) on Jul 08, 2003 at 13:27 UTC
    You can check the $] variable. Please read perldoc perlvar for details. It would look like:
    if ($] < 5.006001) {
        die "You don't have a current version of Perl";
    }
    

    Greetings,
    Janek

      thanks. This:
      if ($] < 5.006001) { die "You don't have a current version of Perl"; }
      didnt work for me for some reason. I checked perldocs and it seems this is the way to do it but for some reason it doesnt check my perl version.

        What does perl -v show? That should tell you what's going on.

        --t. alex
        Life is short: get busy!
Re: Checking Perl version
by QwertyD (Pilgrim) on Jul 09, 2003 at 04:56 UTC
Re: Checking Perl version
by William G. Davis (Friar) on Jul 09, 2003 at 06:51 UTC
    eval { require 5.6.1; }; warn "You do not have the current version of perl." if ($@);
    Although if you plan on exiting, you might as well just do:
    use 5.6.1;
    or:
    require 5.6.1;
    And let Perl do the rest of the work (it die()'s if the verion of Perl on that machine is less than the one you specify).

    (BTW, I believe 5.8.x is the "current" version of Perl, not 5.6.1).