Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: How to get the 'use VERSION' number

Tags:

version

perl

Is there a special variable or a function which gives me the number of use VERSION (in this case 5.12.0) when running the script?

#!/usr/bin/env perl 
use warnings;
use 5.12.0;
like image 262
sid_com Avatar asked Feb 07 '12 08:02

sid_com


People also ask

How do I check perl version?

Type perl -v on a command line to find out which version. ActiveState Perl has binary distributions of Perl for many platforms. This is the simplest way to install the latest version of Perl.

How do I know if a perl module is installed?

Check installed perl modules via terminal Available commands are: l - List all installed modules m <module> - Select a module q - Quit the program cmd? Then type l to list all the installed modules, you can also use command m <module> to select the module and get its information. After finish, just type q to quit.

What is perl version?

Currently latest perl version is 5.24.

What is perl latest version?

Perl 5.36. 0 is the current stable version of Perl.


2 Answers

I just quickly checked feature.pm code - the version itself is not stored anywhere. Alex's answer already showed how to test particular features that results from the call.

Also note that use VERSION can be called on several places (in modules for instance).

One hypothetical option would be to override use and record the version number somewhere for inspection.

Edit: Some poking in the hook direction:

use version; # for version parsing
use subs 'require';
BEGIN {
    sub require {
        warn "use ",version->parse($_[0]);
        # ... emulate original require
    };
}

use 5.12.0;

This limited example reports the version specified, but for real use it would have to be much more robust.

like image 71
bvr Avatar answered Oct 05 '22 07:10

bvr


You can, during compile time, poke about in the hints variable (${^H}) (where dragons lurk) and look into the hints hash (%{^H}) (where dragons lurk, but in a public documented sort of way), this will let you know which specific features are enabled. I don't know how to work out if specifically a feature bundle, or all given features, were requested:

perl -le "use feature qw(:5.12); BEGIN{print $^H;print foreach keys %^H}"
133376
feature_unicode
feature_say
feature_state
feature_switch

perl -le "use 5.12.0; BEGIN{print $^H;print foreach keys %^H}"
134914
feature_unicode
feature_say
feature_state
feature_switch
like image 40
Alex Avatar answered Oct 05 '22 06:10

Alex