How to disable this when given experimental in Perl?

I am moving the old toolchain to the new system, and now I get a lot of notifications given is experimentalor when is experimental.

$ perl -e 'use v5.10; given (12) { when (12) { print "Hello World" }}'
given is experimental at -e line 1.
when is experimental at -e line 1.
Hello World

I want my new system to be fully compatible with the old. By this I mean the exact conclusion.

Is there a way to disable these notifications without touching oneliners and scripts?

+4
source share
1 answer

First of all, please note that smartmatching will be deleted or modified in an incompatible manner. This may affect your instructions given.


To use given+ whenwithout warning, you need the following:

use feature qw( switch );
no if $] >= 5.018, warnings => qw( experimental::smartmatch );

experimental .

use experimental qw( switch );

, , , (, , Perl). .

. , , Perl .

, , , $SIG{__WARN__}, .

$SIG{__WARN__} = sub {
   warn($_[0]) if $_[0] !~ /^(?:given|when) is experimental at /;
};

(, , $SIG{__WARN__}.)

, , , Perl :

export PERL5OPT=-MMonkey::SilenceSwitchWarning

$ cat Monkey/SilenceSwitchWarning.pm
package Monkey::SilenceSwitchWarning;

use strict;
use warnings;

$SIG{__WARN__} = sub {
    warn($_[0]) if $_[0] !~ /^(?:given|when) is experimental at /;
};

1;

$ perl -e 'use v5.10; given (12) { when (12) { print "Hello World\n" }}'
given is experimental at -e line 1.
when is experimental at -e line 1.
Hello World

$ export PERL5OPT=-MMonkey::SilenceSwitchWarning

$ perl -e 'use v5.10; given (12) { when (12) { print "Hello World\n" }}'
Hello World
+6

Source: https://habr.com/ru/post/1674688/


All Articles