Hi perldigious,

... I wouldn't be surprised if there were cases where it made good sense to do so.

I think choroba showed an excellent example of code where it's perfectly ok to pass a closed filehandle to a sub. I think usually it's the job of modules like Perl::Critic to enforce a certain coding style, not the job of warnings.

I agree that validation for a filehandle would be good if it was a trivial thing to do.

The code I showed with Scalar::Util will work in many cases, but not every single one. So it really depends on whether you're coding a module which you intend to release to many users, where the chances are good that someone might try to pass in a valid object that fails the test, or whether you're coding "just" a script where you've got a good overview of the values that are being passed to the sub. If it's the latter, then my approach would probably be to just use the code I showed, and if someday I decide I want to pass in something that fails the check, I can always reevaluate then.

Regarding your other reply about opening the files early in your scripts, note you could use file tests to check on the files at the start of the script so you don't have to open them right away. There is a small chance they might get deleted in between the file test and the open, but there's plenty of situations where one can safely assume that won't happen.

Regards,
-- Hauke D


In reply to Re^3: Propose addition to use warnings? by haukex
in thread Propose addition to use warnings? by perldigious

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.