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

Hi noble Monks,

I can't find anything about this on perldoc and on the net.

I know that if I use 5.012; I get

use strict; use warnings;
but is there somewhere a list that maps $] to its automatically enabled pragmas?

Replies are listed 'Best First'.
Re: Which pragmas are activated with a specific perl version?
by Eily (Monsignor) on Mar 15, 2018 at 11:19 UTC

    warnings is not included by use VERSION (I learned this the hard way, when I ignored a bug because "it can't happen, warnings would have told me") as demonstrated by:

    perl -e "use v5.12; my @b; $a = @b[0]" perl -e "use warnings; my @b; $a = @b[0]" Scalar value @b[0] better written as $b[0] at -e line 1. Name "main::a" used only once: possible typo at -e line 1.

    According to Implicit strictures, use VERSION is equivalent to use strict; use feature ':VERSION';, and I don't think anything as been added since. So you can have the list of what is included by looking in %feature::feature_bundle (you can look at the code of feature for more info on that)

    Edit: "use VERSION does not load the feature.pm" as quoted by LanX, so %feature::feature_bundle isn't available unless you explicitly call use feature...

      " warnings is not included by use VERSION“ Why?

        I don't know, it can't be for retro compatibility reasons because use VERSION is about stating that the code isn't retro compatible anyway. And there is a command switch to enable warnings (-w) but none to enable strict (though -Mstrict would work), I don't know if this is connected.

Re: Which pragmas are activated with a specific perl version?
by LanX (Saint) on Mar 15, 2018 at 11:20 UTC
    from perldoc use

    use VERSION also lexically enables all features available in the requested version as defined by the feature pragma, disabling any features not in the requested version's feature bundle. See feature . Similarly, if the specified Perl version is greater than or equal to 5.12.0, strictures are enabled lexically as with use strict . Any explicit use of use strict or no strict overrides use VERSION , even if it comes before it. Later use of use VERSION will override all behavior of a previous use VERSION , possibly removing the strict and feature added by use VERSION . use VERSION does not load the feature.pm or strict.pm files.

    In perldoc feature each "feature" is listed with the minimal version.

    Like

    The say feature

    use feature say tells the compiler to enable the Perl 6 style say function.

    See say for details.

    This feature is available starting with Perl 5.10.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

      And taking the information from "Feature Bundles":

      # no "use VERSION" is the same as: use feature qw/array_base/; use 5.010; # is the same as: use feature qw/say state switch array_base/; use 5.012; # is the same as: use strict; use feature qw/say state switch unicode_strings array_base/; use 5.014; # is the same as: use strict; use feature qw/say state switch unicode_strings array_base/; use 5.016; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc/; use 5.018; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc/; use 5.020; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc/; use 5.022; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc/; use 5.024; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc postderef_qq/; use 5.026; # is the same as: use strict; use feature qw/say state switch unicode_strings unicode_eval evalbytes current_sub fc postderef_qq/;

      Note the absence of warnings, as already pointed out by Eily.

        Thanks! This answers my question. But I have a new one :-)

        Where did you get this version of the table?

        My perldoc and the web based documentation have a different table:

        The following feature bundles are available: bundle features included --------- ----------------- :default array_base :5.10 say state switch array_base :5.12 say state switch unicode_strings array_base :5.14 say state switch unicode_strings array_base :5.16 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.18 say state switch unicode_strings unicode_eval evalbytes current_sub fc ...
Re: Which pragmas are activated with a specific perl version?
by duelafn (Parson) on Mar 15, 2018 at 13:35 UTC

    Other monks have pointed you at the feature documentation, but I'd like to expand on Anonymous monk's suggestion that you leave use strict; in your scripts even if it is automatically enabled by use 5.012;.

    If you rely on use VERSION; and someone comes along later and modifies the code to run on an older perl version, they will remove or modify the use VERSION which may change the pragmas you are running under, and not all of them will immediately cause errors (losing say would be immediately obvious, but losing strict or unicode_eval would be more subtle).

    Since strict is always relevant, I still include use strict; regardless of version. I consider a comment sufficient for other non-keyword features that I actuall make use of in the code. For example:

    use strict; use warnings; use 5.016; # for unicode_eval and lvalue substr

    Good Day,
        Dean

      I always enable the pragmas explicitly like this (in my nice template for Module::Starter::PBP):

      use 5.014; use strict; use warnings; use utf8; use Carp; ...

      My question was different: I wish to know if there is a table that maps each version with the pragmas it loads automatically.

      I knew about perldoc feature and my question is directly inspired by the table on that doc page's "FEATURE BUNDLES" section.

      The following feature bundles are available: bundle features included --------- ----------------- :default array_base :5.10 say state switch array_base :5.12 say state switch unicode_strings array_base :5.14 say state switch unicode_strings array_base :5.16 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.18 say state switch unicode_strings unicode_eval evalbytes current_sub fc ...
Re: Which pragmas are activated with a specific perl version?
by Laurent_R (Canon) on Mar 15, 2018 at 13:53 UTC
    See also chromatic's Modern::Perl module.

    For example:

    use Modern::Perl '2012";
    will activate the 5.12 features as well as both strict and warnings.

Re: Which pragmas are activated with a specific perl version?
by Anonymous Monk on Mar 15, 2018 at 12:19 UTC
    But please don't rely on this – use multiple pragmas to say what you actually mean.