I think it's no longer true - and I'm struggling to remember how to test it - but I'm pretty sure there used to be the distinction that while (<>) was special-cased to act as while (defined($_ = <>)), while anything more complicated (such as while ($line = <>)) did not get the "defined" check added to it. So if <> were to return something like an empty string, or "0", the latter case could terminate early.

The oldest perl I have to hand is a maint-5.8, and I couldn't reproduce it there with perl -e 'print "0\n0"' | perl -we 'while ($r = <>) { printf "%s", $r }' -, so either I'm testing it wrong, or it affected only even earlier perls, or I'm going senile. (These options are not necessarily exclusive.)

Update but the point was that it could be written by someone with a vague memory that something like that could happen - much like I have - and if so, that didn't necessarily make it awful code.


In reply to Re^3: Critique of some perl code. by hv
in thread Critique of some perl code. by jwkrahn

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.