Warnings are generally there to reduce the risk of you getting yourself into coding trouble, and to let you know that you might be doing something that has unintended consequences. A best practice would be to write clean enough code that you don't trigger warnings. If you are getting a warning, you might want to look at your approach and see if there's something that can be done to clean it up.

Very occasionally you might be doing something intentionally that triggers a warning. In such cases there is the "no warnings qw/warnings list/;" pragma, which can be used to lexically shut off a particular warning. When doing so it is advisable to disable the specific warning in the smallest possible lexical scope so that you still gain the benefit of that warning being active everywhere else in your code.

But for the most part disabling warnings should not be used as a crutch enabling you to go on coding without bothering to learn "a better way." It's a little like the advice many give regarding symbolic references; just because they exist and you can use them doesn't mean that your situation is the special case that tips the "pros/cons" scale in favor of your using them. Nevertheless, Perl gives us symbolic refs so that those who have a true need can use them. Turning off a specific warning in a narrow scope is perfectly fine, provided it's not being done so that you can write buggy and unmaintainable code.

With that introduction, the required reading for selective warnings is perllexwarn -- a document that discusses lexical scoping for warnings and provides a tree of possible warnings.


Dave


In reply to Re: selective warnings by davido
in thread selective warnings by baxy77bax

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.