Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:
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"; }
Produces this output:
---------------------------------------------------------------------- +------------------------------ 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 ---------------------------------------------------------------------- +------------------------------
I have 2 questions, are these 2 lines correct?
line 14 : local $SIG{__WARN__} = \&suppress_UV_warning;
line 50 : warn $message;

In reply to Re: How can I suppress 'uninitialized' warnings in a CPAN module? by zork42
in thread How can I suppress 'uninitialized' warnings in a CPAN module? by zork42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-01-26 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?