use strict; is pretty ubiquitous but I don't even use warnings; all that much (I use "#!/usr/bin/perl -w" a lot).

The point of 'use warnings' was that somebody got annoyed with some module where the author didn't test that their module code didn't generate warnings. But it is certainly less than perfect on a lot of other points.

One big problem is that a lot of warnings are generated more by data than by code. For example:

use warnings; use NotMy::Module qw< setsomestring >; my $input= <STDIN>; setsomestring( $input );

If NotMy/Module.pm doesn't contain use warnings;, then my use warnings; above is powerless to tell me that I've failed to check for an end-of-file and have just passed undef to a function that isn't meant to deal with undef (and just acted like I passed it an empty string which is a bug and something I wanted to know about).

The converse is also a problem:

no warnings; use NotMy::Module qw< setsomestring >; my $input= <STDIN>; setsomestring( $input );

Here, "no warnings;" means that I'm coding in a mode where I don't want to have to write a bunch of obnoxious trivia like $input= '' if ! defined $input; all over the place and I actually want end-of-file to result in setsomestring() acting like I gave it an empty string. And yet, the new version of NotMy/Module.pm says use warnings; so I still get annoyed by those way-too-common "undef" warnings.

The better (but in-a-perfect-world) solution for the original problem of people who don't test whether their modules generate warnings (even when never given data by the module user that could be blamed for the warning) would actually be to get such module authors to mark their modules with no warnings;. That requires a perfect world because people who don't care about warnings aren't likely to insert no warnings; for the sake of the rest of us.

Luckily for me, the ubiquity of 'use warnings' in the hive mind means that I almost never run into the original problem these days. So my Perl scripts tend to start with "#!/usr/bin/perl -w" and not to 'use warnings'. If I find a warning-generating module, then I deal with that, but I rarely have to.

My modules tend to also not 'use warnings' but my module test scripts also start with #!/usr/bin/perl -w so I try to make sure that my modules don't generate warnings. But I let the users of my modules decide whether or not they want to get warnings when they use my modules.

(But, no, that isn't a perfect solution, either.)

- tye        


In reply to Re: Common uses of "use" (warnings?) by tye
in thread Common uses of "use" by mjscott2702

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.