http://www.perlmonks.org?node_id=1035295


in reply to What is the impact of 5.18.0?

A further annoyance with the experimental features is that "use 5.018;" only enables some of them (e.g. 'smartmatch' is enabled while 'lexical_subs' is not). In addition, it would be useful if the error or warning messages actually stated what the related feature was (or vice versa).

Here's some examples.

This produces warnings about given and when (you need to know that the feature is smartmatch) and an error about "my" subs (you need to know that the feature is lexical_subs):

$ perl -Mstrict -Mwarnings -e ' use 5.018; my ($x, $y) = (1, undef); given ($x) { when (1) { say "\$x == 1" } default { say "\$x != 1" } } given ($y) { when (1) { say "\$y == 1" } default { say "\$y != 1" } } my sub z { say "In z()" } z(); ' given is experimental at -e line 4. when is experimental at -e line 5. given is experimental at -e line 8. when is experimental at -e line 9. Experimental "my" subs not enabled at -e line 12.

Also potentially confusing, is that the warnings are not emitted if the error is emitted first:

$ perl -Mstrict -Mwarnings -e ' use 5.018; my sub z { say "In z()" } my ($x, $y) = (1, undef); given ($x) { when (1) { say "\$x == 1" } default { say "\$x != 1" } } given ($y) { when (1) { say "\$y == 1" } default { say "\$y != 1" } } z(); ' Experimental "my" subs not enabled at -e line 3.

Enabling lexical_subs in the first example, the code runs but with lots of warnings. Note the warnings inconsistency of given/when mentioning the code but not the feature and lexical_subs mentioning the feature but not the code (which, in itself, is inconsistent with the lexical_subs error mentioning the code but not the feature):

$ perl -Mstrict -Mwarnings -e ' use 5.018; use feature "lexical_subs"; my ($x, $y) = (1, undef); given ($x) { when (1) { say "\$x == 1" } default { say "\$x != 1" } } given ($y) { when (1) { say "\$y == 1" } default { say "\$y != 1" } } my sub z { say "In z()" } z(); ' given is experimental at -e line 5. when is experimental at -e line 6. given is experimental at -e line 9. when is experimental at -e line 10. The lexical_subs feature is experimental at -e line 13. $x == 1 $y != 1 In z()

Adding 2 more lines of code to get rid of the warnings:

$ perl -Mstrict -Mwarnings -e ' use 5.018; use feature "lexical_subs"; no if $] >= 5.018, warnings => "experimental::smartmatch"; no if $] >= 5.018, warnings => "experimental::lexical_subs"; my ($x, $y) = (1, undef); given ($x) { when (1) { say "\$x == 1" } default { say "\$x != 1" } } given ($y) { when (1) { say "\$y == 1" } default { say "\$y != 1" } } my sub z { say "In z()" } z(); ' $x == 1 $y != 1 In z()

[In the above examples, replacing -e with -E and removing use 5.018; produces the same result.]

While something of a contrived point, I do note that the additional code I had to add in order to remove all of the warnings is of an equivalent size to the warnings themselves.

-- Ken