9

I've seen several posts that state use 5.12.0; in Perl enables certain features/pragmas by default (e.g., use strict;). Another example is in UTF-8 and perl where it is stated that use 5.14.0; is

optimal for Unicode string feature UTF-8 handling.

I seem to recall an available use declaration that provides certain defaults (e.g., use strict; use warnings; use diagnostics;), but can't remember the specifics. How does one find out what is included in a given use 5.##.#; statement? For example, what does use 5.22.0; provide by default? use strict;?

divibisan
  • 11,659
  • 11
  • 40
  • 58
secJ
  • 499
  • 3
  • 12

3 Answers3

12

This is documented in perldoc feature:

It's possible to load multiple features together, using a feature bundle. The name of a feature bundle is prefixed with a colon, to distinguish it from an actual feature.

use feature ":5.10";

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
:5.20     say state switch unicode_strings
          unicode_eval evalbytes current_sub fc
:5.22     say state switch unicode_strings
          unicode_eval evalbytes current_sub fc

where

use v5.10.0;

will do an implicit

no feature ':all';
use feature ':5.10';

and so on.

Automatic enabling of strictures is documented in perldoc -f use:

if the specified Perl version is greater than or equal to 5.12.0, strictures are enabled lexically as with use strict.

ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
  • Perfect. This is exactly what I was looking for. Was I imagining it, or is there some `feature` subset that includes: strictures, warnings and diagnostics all in one go? Thanks – secJ Jul 07 '15 at 00:08
  • As far as I know, there's nothing in core that does that, but there could certainly be modules that do it. Perhaps you're thinking of [Modern::Perl](https://metacpan.org/pod/Modern::Perl), which enables `strict`, `warnings`, and all 5.10 features, among other things. – ThisSuitIsBlackNot Jul 07 '15 at 00:10
  • Ah, yes, that's it! Modern::Perl. Thanks again – secJ Jul 07 '15 at 00:13
  • 1
    there's also [common::sense](http://p3rl.org/common::sense) and [Defaults::Modern](http://p3rl.org/Defaults::Modern) and probably others I can't remember – ysth Jul 07 '15 at 00:22
2

use 5.12.0; does use feature ':5.12';, so you get

  • say
  • state
  • switch
  • unicode_strings
  • array_base

The feature bundles are documented in feature.pm's documentation.

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Thanks for the link to features.pm's documentation. Great resource to keep bookmarked – secJ Jul 07 '15 at 00:14
2

For enhancements not covered by feature, you can use Syntax::Construct.

choroba
  • 231,213
  • 25
  • 204
  • 289