Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding Warnings that Relate to Intentional Code in Perl

Tags:

perl

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.

like image 735
Timothy R. Butler Avatar asked Oct 24 '25 14:10

Timothy R. Butler


1 Answers

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);   # emits warning
{
    no warnings 'uninitialized';
    print join(":", @c); # warning suppressed
}
like image 110
mob Avatar answered Oct 26 '25 06:10

mob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!