Ok - so it sounds like you agree that the return value of calls like open and opendir should always be checked. Whether or not the result of a failed call is to cause the program to abort is definitely a matter of design.

However, note that there are at least two other ways to catch an open ... or die. There's $SIG{__DIE__}, and there's eval, the latter of which can be made even more useful by a module like Try::Tiny. For CGI scripts, there's CGI::Carp, and other web frameworks have similar ways of gracefully handling errors. And when correctly configured, cron will email warning and error messages to someone who can deal with them.

Also, since you so clearly state that 'There are only two situations where you should use "open or die".' and 'a plethora of situations where "open or die" is definitely not the right thing to do', I'm going to disagree with you there, on a more philosophical note. You said 'I didn't bother with the "die" or an "else" statement' - in a situation like that, I would still always write either ... or die $!; or at least warn if it really is acceptable for the program to continue in the case of a failure like that (and in my experience, those are much more rare than the cases where it's better to die).

Code has a way of sneaking into production; copy & paste is many a programmer's best friend. In the case of the code in question, the opendir could fail silently, and the program would give the wrong result; if it had warnings enabled, it would give confusing messages like "readdir() attempted on invalid dirhandle" to the user instead of "Failed to opendir /foo/bar: Permission denied" (and that it's better to Use strict and warnings is attested to by the fact that the code contained a mistake that warnings would have helped catch). So I still say it's better to always, always die or otherwise handle the error.


In reply to Re^6: pushing file counts for adding by Anonymous Monk
in thread pushing file counts for adding by flieckster

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.