Kirti S
Kirti S

Reputation: 113

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

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.

Upvotes: 11

Views: 4932

Answers (2)

amphetamachine
amphetamachine

Reputation: 30595

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"

Upvotes: 6

nire
nire

Reputation: 458

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.

Upvotes: 12

Related Questions