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

后端 未结 3 1970
甜味超标
甜味超标 2021-01-01 14:06

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 feat

相关标签:
3条回答
  • 2021-01-01 14:15

    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);
    }
    
    0 讨论(0)
  • 2021-01-01 14:16

    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.

    0 讨论(0)
  • 2021-01-01 14:33

    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.

    0 讨论(0)
提交回复
热议问题