[Bloomington-normal-pm] Finding the version of Perl: $] vs. $^V

Phil Winans pawinan at ilstu.edu
Thu Nov 7 10:33:37 CST 2002


Last night at the meeting Chuck pointed out that $] can be used to return
the version of Perl.

This is true:
perl -wle 'print $]' => 5.006001

Marc mentioned that the method he was using to get the version of Perl
wasn't giving pretty output when printed.

perldoc perlvar for 5.6.x has the answers:
Regarding $]:
             The use of this variable is deprecated.  The
             floating point representation can sometimes lead to
             inaccurate numeric comparisons.  See "$^V" for a
             more modern representation of the Perl version that
             allows accurate string comparisons.

And for $^V (which didn't exist prior to 5.6.0):
     $^V     The revision, version, and subversion of the Perl
             interpreter, represented as a string composed of
             characters with those ordinals.  Thus in Perl v5.6.0
             it equals "chr(5) . chr(6) . chr(0)" and will return
             true for "$^V eq v5.6.0".  Note that the characters
             in this string value can potentially be in Unicode
             range.

So since $] is deprecated and we want to use $^V, the best method
I can think of for nicely printing the version in $^V is this:
perl -wle 'print join(".", map(ord, split(//, $^V)))' => 5.6.1

--
Phil Winans - pawinan at ilstu.edu
Network Engineer
Telecommunications and Network Support Services
Illinois State University




More information about the Bloomington-normal-pm mailing list