clt60
clt60

Reputation: 63902

Perl: What exact features does 'use 5.014' enable?

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.

Upvotes: 22

Views: 4950

Answers (3)

larsen
larsen

Reputation: 1431

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);
}

Upvotes: 28

Telemachus
Telemachus

Reputation: 19705

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.

Upvotes: 4

Sherm Pendley
Sherm Pendley

Reputation: 13612

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.

Upvotes: 4

Related Questions