Home > Archive > PERL Beginners > May 2006 > suppressing selected warning messages
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
suppressing selected warning messages
|
|
| Gavin Bowlby 2006-05-24, 6:58 pm |
| All:
Is there a way to suppress a specific warning message produced by Perl?
Example program:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
use strict;
use warnings;
my $a =3D "abc";
if ($a =3D=3D 7) {
print "a =3D 7\n";
}
else {
print "a !=3D 7\n";
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Output from Perl debugger when this program is run:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D
$ perl -d test.pl
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(test.pl:4): my $a =3D "abc";
DB<1> s
main::(test.pl:6): if ($a =3D=3D 7) {
DB<1> s
Argument "abc" isn't numeric in numeric eq (=3D=3D) at test.pl line 6.
at test.pl line 6
main::(test.pl:10): print "a !=3D 7\n";
DB<1> s
a !=3D 7
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<1>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D
I can suppress all warning checks by doing a:
no warnings;
if ($a =3D=3D 7) {
use warnings;
but I would like all other "normal" Perl warnings to be used for the
statement:
if ($a =3D=3D 7)
other than the check for the LHS of the equality check being a numeric
value.
Is this possible?
Regards,
Gavin Bowlby
| |
| usenet@DavidFilmer.com 2006-05-24, 6:58 pm |
| Gavin Bowlby wrote:
> All:
>
> Is there a way to suppress a specific warning message produced by Perl?
perldoc perllexwarn
> but I would like all other "normal" Perl warnings to be used
You will notice the perldocs stipulate a "numeric" category; ie:
no warnings 'numeric';
--
http://DavidFilmer.com
| |
| Xavier Noria 2006-05-24, 6:58 pm |
| On May 24, 2006, at 18:48, Gavin Bowlby wrote:
> I can suppress all warning checks by doing a:
>
> no warnings;
> if ($a == 7) {
> use warnings;
>
> but I would like all other "normal" Perl warnings to be used for the
> statement:
>
> if ($a == 7)
>
> other than the check for the LHS of the equality check being a numeric
> value.
>
> Is this possible?
Warnings have a hierarchy documented in perllexwarn. The category
each warning belongs to is documented in perldiag. In that case the
most you can do is to disable the "numeric" category, which is the
one that warning belongs according to perldiag:
{
no warnings qw(numeric);
# issues "use of uninitialized ..." but not the "numeric" one
print undef if "foo" == 0;
}
-- fxn
|
|
|
|
|