Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print out the version of perl being run, from the perl script itself?

Tags:

version

perl

I have multiple versions of Perl installed.

I have specified which version to use. But to verify, I would like to output the version of Perl from the .pl script itself.

Is this possible?

Parsing the output of "perl --version" seems syntactically wrong in Perl scripting.

like image 832
Kirti S Avatar asked Oct 28 '14 10:10

Kirti S


2 Answers

Use the predefined Perl variable $] or the more current $^V within a perl script:

print "Perl version: $]\n";

Example output:

Perl version: 5.018002

(Perl 5.18.2)

For more special variables, please see perlvar or http://www.kichwa.com/quik_ref/spec_variables.html.

like image 127
nire Avatar answered Nov 01 '22 15:11

nire


The Perl version is stored in a couple of different Perl special variables:

#!/usr/bin/perl
print "$^V\n";                   # "v5.32.0"
print "$]\n";                    # "5.032000"

If you're using use English, you have additional aliases for these variables:

use English;
print "$PERL_VERSION\n";         # "v5.32.0"
print "$OLD_PERL_VERSION\n";     # "5.032000"
like image 39
amphetamachine Avatar answered Nov 01 '22 14:11

amphetamachine