Whilst warnings do tend to follow the data; doesn't their significance (benign or actionable) depend upon the purpose/function of the code manipulating that data?

Either that, or the purpose of the code creating that data.

Enabling or disabling some warnings at some localized scope can certainly be useful. The short-comings of warnings.pm are only partial.

You could repair some of the shortcomings of warnings.pm by allowing subs to declare that they want string values or numeric values (well, for positional arguments), such that the conversion from scalar to string/number would happen in the context of the call to the sub rather than inside the sub when the arguments are extracted or even later when they are finally put to real use.

You could also repair them by providing a way for a sub to request code to be run with the caller's warnings settings. Then a careful module author could go to the effort to "cast" any provided values to the more-specific type in a way that would only cause a warning if the caller wanted to hear that type of warning.

sub careful { my( $string, $number ) = @_; { use warnings ':caller'; $string = "$string"; $number = 0+$number; } ... }

You could also put the onus on the author of the calling code. This doesn't make much sense to me in the case of the caller not wanting warnings, but I can see it making sense when the caller wants warnings but the called sub doesn't have warnings enabled:

use warnings; ... sloppy( "$string", 0+$number );

These relatively few data-specific warnings might be rather insignificant if it weren't for the fact that "uninitialized" warnings are probably the single most common warning both in terms of how likely they are to happen and in how often people want to ignore them.

Though, I'm not advocating for such feature enhancements to Perl. I'm happy with my "-w" and (newly adopted) "-X".

- tye        


In reply to Re^7: Shebang behavior with perl (scope) 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.