In the perllexwarn are defined all warnings what is possible to set.
But here is nothing about, how to print out what warnings i have currently enabled.
E.g.:
use strict;
use warnings;
print warnings::enabled->pretty_print(); #fictional...
How is it possible?
example:
use strict;
use 5.012;
use warnings;
my $aaa;
say "$aaa";
say warnings::enabled("uninitialized") ? "yes" : "no";
The above will output:
Use of uninitialized value $aaa in string at y line 6.
no
so, the "uninitialized" warning category is "set", because its prints a warning, but the warnings::enabled("uninitialized")
not returns true
.
Warnings in Perl can be created by using a predefined function in Perl known as 'warn'. A warn function in Perl generates a warning message for the error but will not exit the script. The script will keep on executing the rest of the code.
Strict and Warning are probably the two most commonly used Perl pragmas, and are frequently used to catch “unsafe code.” When Perl is set up to use these pragmas, the Perl compiler will check for, issue warnings against, and disallow certain programming constructs and techniques.
Reading perllexwarn
... functions that are useful for module authors. These are used when you want to report a module-specific warning to a calling module has enabled warnings via the "warnings" pragma.
If I understand it correctly, it means the functions (enabled
, warnif
) only work for module-specific warnings, not for the standard categories. (There is probably a missing "that" before "has" in the documentation.)
Update: It seems standard categories work as well, but only in a module:
package MY;
use warnings::register;
sub S {
my $x;
print $x, "\t";
print warnings::enabled("uninitialized"),"\n";
}
package main;
use warnings;
MY::S();
no warnings;
MY::S();
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