You missed the real point. This has nothing to do with whether Perl "automatically" checks undef. The real point here is that, under a normal situation without set $/, you don't get a real empty string or a "0" back, so those posibilities are eliminated, and this leaves undef the only condition that may evaluate $line to false, thus the use of "defined" is not neccessary here.

But it is possible to get a false value back without changing $/, if the last "line" consists of a single 0 with no terminating newline. And you can see the effect of losing the defined check if you add something else to the conditional (perl only supplies the defined test when the condition is a plain read operator or read operator with assignment (control D to end input without final newline):

:~$ cat > OOPS 3 2 1 0^D :~$ perl -e '$foo = 42; while($foo and $_ = <>){print}' OOPS 3 2 1 :~$ :~$ perl -e '$foo = 42; while($foo and defined($_ = <>)){print}' OOPS 3 2 1 0:~$

So the possibility of losing data without defined exists regardless of what value is assigned to $/.


In reply to Re: Re: Re^2: To Kill a Meme: while(defined($line = <>)) by Anonymous Monk
in thread To Kill a Meme: while(defined($line = <>)) by sauoq

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.