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

My remote web server provider does not allow direct UNIX access, so I had to find out the version of Perl through the statement: print "$]\n";

It reported 5.006001.

Other messages on this site have taught me that the actual version of Perl may be several versions beyond this reported value. Is there an alternative expression I can use in a CGI script to return a more precise Perl version number?

Replies are listed 'Best First'.
Re: version reporting beyond print "$]\n";
by eibwen (Friar) on May 09, 2005 at 03:25 UTC

    `perl -we 'print $], $/;'` returns 5.008004. However this value does not imply v5.008004; rather v5.8.4 as explained in perlvar. Similarly, 5.006001 is not v5.006001 but rather v5.6.1.

    UPDATE: Or if you'd rather use $^V:

    print join '.', map { ord $_ } split(//, $^V);

      An easier methd is
      printf "%vd",$^V ;


      Manav
Re: version reporting beyond print "$]\n";
by davido (Cardinal) on May 09, 2005 at 04:35 UTC

    If you're trying to make sure a script only runs under a specific (or later) version, there is always:

    use strict; use warnings; require 5.8.1;

    And if you don't want that to be fatal, you can do this:

    use strict; use warnings; eval "require 5.8.1;"; if ( $@ ) { print "Nice try!\n$@"; } else { print "Thanks for not asking to run me under Perl 4.\n"; }

    Dave

Re: version reporting beyond print "$]\n";
by manav (Scribe) on May 09, 2005 at 03:24 UTC
    Dunno if this is better but still
    $a=`perl -v` ##or `perl -V` print $a


    Manav
Re: version reporting beyond print "$]\n";
by bluerattle (Initiate) on May 09, 2005 at 04:43 UTC
    Thanks for the tips. I tried the suggested

    print join '.', map { ord $_ } split(//, $^V);

    And the result was 5.6.1, which of course is consistent with the 5.006001 returned by print "$]\n";

Re: version reporting beyond print "$]\n";
by mrborisguy (Hermit) on May 09, 2005 at 03:28 UTC
Re: version reporting beyond print "$]\n";
by ambrus (Abbot) on May 09, 2005 at 06:42 UTC

    There's also use Config; print $Config{version}, "\n"; but I'd trust $] more.

    If you really don't trust these, there are some features that can easily be tested with a few lines of code and are present in only from some versions: pack "U", pack "x!", pack "j", pack "x[L]", 3-arg open, stringstream open, \&Encode::is_utf, dump, [[::]] character classes, $^N, the EQ operator, open($fh, "+>", undef). However, some of these can cause surprising results if the perl you are using is compared with strange conffigure settings (like no perlio).