in reply to How can I suppress 'uninitialized' warnings in a CPAN module?
Thank you everyone for your comments!
I suppose the easiest solution would be to edit Tokenizer.pm, but part of me thinks that is a Bad Thing! ;)
I tried LanX's generic solution and it seems to work very well:
line 14 : local $SIG{__WARN__} = \&suppress_UV_warning;
line 50 : warn $message;
I suppose the easiest solution would be to edit Tokenizer.pm, but part of me thinks that is a Bad Thing! ;)
I tried LanX's generic solution and it seems to work very well:
Produces this output:use warnings; use strict; p(); print "Test 1\n\n"; print undef; # "Use of uninitialized value in print at . +.." print 'a'+1; # "Argument "a" isn't numeric in addition ( ++) at ..." foo(1); p(); { local $SIG{__WARN__} = \&suppress_UV_warning; # <-------- Is th +is correct ? p(); print "Test 2\n\n"; print undef; # SUPPRESSED! "Use of uninitialized value i +n print at ..." print 'a'+1; # "Argument "a" isn't numeric in addition ( ++) at ..." foo(2); p(); } p(); print "Test 3\n\n"; print undef; # "Use of uninitialized value in print at . +.." print 'a'+1; # "Argument "a" isn't numeric in addition ( ++) at ..." foo(3); p(); # generate some more warnings to check they are suppressed here too sub foo { my ($x) = @_; print "\n\n"; print undef; # SUPPRESSED IN TEST 2! "Use of uninitializ +ed value in print at ..." print "foo $x" + 1; # "Argument "foo n" isn't numeric in additi +on (+) at ..." } # suppress "Use of uninitialized value" warnings only sub suppress_UV_warning { my ($message) = @_; if ($message =~ /^Use of uninitialized value/) { return; } warn $message; # <-------- Is this correct ? } # print separating line sub p { print "\n", '-'x100, "\n"; }
I have 2 questions, are these 2 lines correct?---------------------------------------------------------------------- +------------------------------ Test 1 Use of uninitialized value in print at D:\test\test.pl line 7. Argument "a" isn't numeric in addition (+) at D:\test\test.pl line 8. 1 Use of uninitialized value in print at D:\test\test.pl line 38. Argument "foo 1" isn't numeric in addition (+) at D:\test\test.pl line + 39. 1 ---------------------------------------------------------------------- +------------------------------ ---------------------------------------------------------------------- +------------------------------ Test 2 Argument "a" isn't numeric in addition (+) at D:\test\test.pl line 19. 1 Argument "foo 2" isn't numeric in addition (+) at D:\test\test.pl line + 39. 1 ---------------------------------------------------------------------- +------------------------------ ---------------------------------------------------------------------- +------------------------------ Test 3 Use of uninitialized value in print at D:\test\test.pl line 27. Argument "a" isn't numeric in addition (+) at D:\test\test.pl line 28. 1 Use of uninitialized value in print at D:\test\test.pl line 38. Argument "foo 3" isn't numeric in addition (+) at D:\test\test.pl line + 39. 1 ---------------------------------------------------------------------- +------------------------------
line 14 : local $SIG{__WARN__} = \&suppress_UV_warning;
line 50 : warn $message;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How can I suppress 'uninitialized' warnings in a CPAN module?
by LanX (Saint) on Nov 17, 2013 at 23:04 UTC |
In Section
Seekers of Perl Wisdom