Home > Mobile >  Hiding Warnings that Relate to Intentional Code in Perl
Hiding Warnings that Relate to Intentional Code in Perl

Time:12-23

I have several warnings like the following that show up a lot when Perl is interpreting my code:

 Smartmatch is experimental at /home/user/www/cgi-bin/safari/lib/SAFARI/Data.pm line 395.

And several from where I override a CPAN module's subroutine that contains bugs:

 Subroutine Net::Amazon::S3::Client::Object::put_part redefined at /usr/local/share/perl5/FaithTree/Backup.pm line 65.

Both of these are intentional things in the code. I've found Smartmatch a wonderful tool that I'm intentionally using without any issues and I overrode those subroutines specifically because they didn't function properly in the upstream module. Is there a "proper" way to tell Perl not to show such warnings? If there's some need for them still, is there proper way to at least rein them in so it doesn't overwhelm server logs?

I read over on another question that I could use use experimental qw(smartmatch switch); to hide the Smartmatch warning. But I'm less certain what to do about the redefinition warning.

CodePudding user response:

use experimental qw(feature ...);

to use experimental features without warnings. To suppress other warnings, run your code with a no warnings ... pragma enabled as described in the perldoc

no warnings 'redefine';
sub Someone::Elses::Package::my_monkey_patch_func { ... }

@c = (1, 2, undef, 4);
print join(";", @c);
{
    no warnings 'uninitialized';
    print join(":", @c);
}
  •  Tags:  
  • perl
  • Related