I'd still check for an open failure for a couple of reasons.

  1. It's a strong habit. That is to say that I'd be checking for failure because I'm not really thinking about it.
  2. Future-proofing code (as already suggested by jbert). Just because I have nothing to fear today does not mean there will be nothing to fear tomorrow.
  3. It makes it easier to modify later. I may want to change it to use a real file. And then I may want to go back. I'd rather just have the die there all the time than keep adding and deleting it.
  4. I'm frequently surprised by things that don't work. In particular, it seems that open has many many special cases. Especially if my code has to deal with someone else's code, it's better to be defensive.

In reply to Re: Checking success of open() on file held in scalar ref. by kyle
in thread Checking success of open() on file held in scalar ref. by johngg

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.