If the open is successful it will return the first line in the file that was passed as a parameter when the function was called. If the open is unsuccessful, the logical short circuit stops at the open, and returns what it returned upon failure, which is undef.

It's important to observe that one must test explicitly whether the return value is "defined". In an error condition, it will not be. Testing the return value for truth/falsehood isn't sufficient, since the first line of a file could be a value that Perl considers false.

Update: I had kinda lost track of this thread, not realizing that there had been additional discussion. But Skeeve correctly pointed out to me that his explanation in Re: what is the return value is accurate, and mine isn't. The flaw in my analysis is that the my $in variable will not have been instantiated. My analysis would have been accurate had $in been pre-declared ahead of the open, but it wasn't, and Skeeve's analysis is spot on.


Dave


In reply to Re: what is the return value by davido
in thread what is the return value by arasumg

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.