Note that there are still plenty of places where it makes sense to use defined inside a while loop. This is specifically a plea to avoid it in cases where you are reading from a filehandle like this: while( defined( $line = <FH> ) ) and nothing more.

I may be blunt in this regard, but if there is a meme that should be killed in any non-oneliner programs, it's the absence of using defined() while reading from a file handle. It just adds too much extra processing when trying to read source code, especially when you have experience in other programming languages. This property of while is different from other conditional constructs, and it's even different from itself when not readng from a file handle (as you yourself point out).

This is completely seperate from any warnings that Perl may have had in the past. This is about maintainability of Perl source code.

As Juerd and others already pointed out: there is no harm in using defined() in these cases. And the extra characters typed easily offset any time lost when someone tries to read the source code later.

To me, the request to please stop using defined() when reading from a file handle, is almost the same as a request to please stop documenting your programs. It's penny wise, but pound foolish.

Liz


In reply to Re: To Kill a Meme: while(defined($line = <>)) by liz
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.