I am currently using the XML::LibXML
module in my Perl script. The XML::LibXML
module we're currently using on our machines was compiled against a newer version of the libxml2
library, and the use statement generates the following warning:
Warning: XML::LibXML compiled against libxml2 20708, but runtime libxml2 is older 20706
The warning does not affect the performance of my script. I've spoken to my supervisor and she says that the error can be completely ignored for our current purposes. Is there any way to temporarily turn off this warning without turning off ALL warnings? I tried to enclose the use
statement inside of a code block {}
and turned off warnings with no warnings;
, but I still got the warning.
You can inhibit warnings, even those like this one that are issued as a result of an explicit call to the warn
function, by setting $SIG{__WARN__}
.
A simple working example (improved thanks to ysth's comment):
mod.pm:
package mod;
sub method {
print "This is mod::method\n";
}
warn "WE DO NOT WANT THIS WARNING\n";
1;
foo.pl:
#!/usr/bin/perl
use strict;
use warnings;
BEGIN {
local $SIG{__WARN__} = sub {};
require mod;
mod::->import();
}
warn "Normal warnings work\n";
mod::method();
The output is:
Normal warnings work
This is mod::method
and I've confirmed that commenting out the setting of $SIG{__WARN__}
causes the "DO NOT WANT" warning to appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With