in reply to To Kill a Meme: while(defined($line = <>))

Huh. I've never seen that line. I guess it means that I'm a relative Perl newbie, huh? (The first version of Perl that I seriously used was 5.6, though there was some very minor dabbling with Perl 4-something)

All of my file readings that use while loops pretty much use the syntax while(chomp($line = <FH>)) already...

Replies are listed 'Best First'.
Re: Re: To Kill a Meme: while(defined($line = <>))
by ChemBoy (Priest) on Nov 03, 2003 at 06:11 UTC
    while(chomp($line = <FH>))

    This is probably a more dangerous meme than while($line = <>) ever was—if your file is missing a terminal linefeed (or CRLF, as the case may be) you'll skip the last line. Not a common failing of text files, but all you need is one for it to bite you, hard.



    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

      Huh. Learn something new every day. Thanks for the heads up.
Re: To Kill a Meme: while(defined($line = <>))
by Abigail-II (Bishop) on Nov 03, 2003 at 09:36 UTC
    All of my file readings that use while loops pretty much use the syntax while(chomp($line = <FH>) already...

    You aren't by any chance the author of the Perl books that are in use by HP-Education, are you? For a long time I thought that the Perl books SUN-Education made were the worst Perl books ever made, but then I got to see the HP books, full of gems like while(chomp($line = <FH>).

    Abigail

      Nope, no authorship here. Especially not for anything on Perl.

      And while I can't say that I am really happy to have provided an example of a "gem" that you think is the worst Perl ever, I do appreciate knowing that this isn't the prescribed way to do things. I've never had this bite me, but it's good to know that it has big teeth.