You are passing an undef into a module that has an unstated (and there is the issue) requirement that the value passed in is not undef.

No. A module provides a sub that needs to be passed a string and a number. I pass in undef() for the string and I pass in '42mph' for the number. Those are fine values because I intentionally didn't turn on warnings. But values get passed in to subs as scalars, not as strings or a numbers, so it is inside of the sub that these scalar values get interpreted as a string and as a number. The module's author followed "best practices" (or "cargo cult") and so added "use warnings;". So I get warnings that I didn't ask for and that I don't want.

If I wanted to jump through extra hoops to avoid being warned about the nature of these values, then I would have turned on warnings.

So I prefer to not "use warnings" in my modules (and to use "-w" in my module tests and even to test that no warnings are emitted in my module tests).

In a tool that non-technical people will run, I don't use "-w" (because warnings usually do more harm than good when shown to non-technical people). In most other scripts, I use "-w" and am sometimes glad that I got told about warnings that happened inside of some module (that I didn't write but that still didn't do "use warnings;").

"use warnings" didn't actually solve the problem of "getting unwanted warnings from modules". It just shifted the problem.

If I was forced to frequently use a module that generates warnings internally (not just from values I pass in), I'd likely add a $SIG{__WARN__} hook to suppress such and continue to use "-w" (if I was unable to institute a deploy step that adds "no warnings" to each new version of that module), at least so I could continue to get warnings from any non-problematic modules that didn't "use warnings;".

Others may choose to use "-X" to deal with unwanted warnings from modules that include "use warnings". Since warnings so often follow data, I find tying warnings to blocks of code to just not be a great approach.

- tye        


In reply to Re^5: Shebang behavior with perl (-w) by tye
in thread Shebang behavior with perl by McKreeger

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.