22

What exactly does 'use 5.014' enable?

Please, someone copy&paste here, because i was not able find it in any perldoc. (maybe i'm blind). In the 'perldoc feature' are only some things for the 5.10. Or point me to some URL.

thanx.

EDIT:

Please first check, what do you reply. For example: try this:

use 5.008;
$s=1;
say "hello";

You will get error message about the "say", because perl 5.8 doesn't know "say"

after, try this:

use 5.014;
$s=1;
say "hello";

you will get error

Global symbol "$s" requires explicit package name 

so, the "use 5.014" enabling use strict, and use feature 'say'; - by default.

David
  • 282
  • 1
  • 17
clt60
  • 62,119
  • 17
  • 107
  • 194

3 Answers3

28

Besides what raj correctly said about the error messages you'd receive if using use 5.014 with an older version of Perl, you can find a list of features enabled reading the source code of feature. The relevant part is near the top:

my %feature_bundle = (
    "5.10" => [qw(switch say state)],
    "5.11" => [qw(switch say state unicode_strings)],
    "5.12" => [qw(switch say state unicode_strings)],
    "5.13" => [qw(switch say state unicode_strings)],
    "5.14" => [qw(switch say state unicode_strings)],
);

The strict bit part is buried somewhat deeper in the code for the interpreter itself. If you look into pp_ctl.c for tag v5.11.0:

/* If a version >= 5.11.0 is requested, strictures are on by default! */

if (PL_compcv && vcmp(sv, sv_2mortal(upg_version(newSVnv(5.011000), FALSE))) >= 0) {
    PL_hints |= (HINT_STRICT_REFS | HINT_STRICT_SUBS | HINT_STRICT_VARS);
}
Community
  • 1
  • 1
larsen
  • 1,431
  • 2
  • 14
  • 26
  • Thanx for the pointer. Only doesn't see in the source the "use strict;". – clt60 Jun 20 '11 at 12:11
  • Excellent answer - thanks for finding the source that helps to specify what each bundle brings in. One question: `strict` is also auto-enabled (as of 5.12, as I recall). Do you know where/when that gets done? (It's not listed in `feature`'s source code, so far as I can tell. – Telemachus Jun 20 '11 at 12:13
  • Terrific - thanks. (Yours really should be the accepted answer.) – Telemachus Jun 20 '11 at 12:26
4

The use x.x.x pragma does turn on some features, and it's easy enough to test this:

#!/usr/bin/env perl
use warnings;
use 5.14.0;

say "hello world!"

Runs great; outputs "hello world!".

#!/usr/bin/env perl
use warnings;
# use 5.14.0;

say "hello world!"

Flaming death; outputs this error message:

Unquoted string "say" may clash with future reserved word at foo line 5.
String found where operator expected at foo line 5, near "say "hello world!""
    (Do you need to predeclare say?)
syntax error at foo line 5, near "say "hello world!""
Execution of foo aborted due to compilation errors.

I'm not, however, 100% sure which features are turned on as of 5.14.0. I believe that you get say, state, switch, unicode_strings and strict.

Telemachus
  • 19,459
  • 7
  • 57
  • 79
4

In newer Perls (starting with 5.10 I think) use 5.x does an implicit use feature ':5.x' Reading through the perldeltas for 5.12 & 5.14, I see a unicode-related feature added in 5.12, but it appears nothing new was added in 5.14.

Sherm Pendley
  • 13,556
  • 3
  • 45
  • 57
  • THANX for pointing me to the "deltas", where: Using the use VERSION syntax with a version number greater or equal to 5.11.0 will lexically enable strictures just like use strict would do (in addition to enabling features.) THANX!!! – clt60 Jun 20 '11 at 12:14
  • also see this answer: http://stackoverflow.com/questions/6050031/why-are-use-warnings-use-strict-not-default-in-perl/6050340#6050340 – matthias krull Jun 20 '11 at 12:20