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

Usually, it doesn't do anything. (...) In order for it to do anything at all, you have to be either A) using a perl <= 5.00404 or B) doing something more complex in your while loop than a simple assignment from a filehandle read and one of the following must be true: 1) you are reading fixed length records and retrieve a record containing all '0's, 2) you have set $/ to a string of one or more '0's, or 3) the last line of a file you are reading must contain a string of one or more '0's and not be terminated with $/.

So by routinely adding 9 characters that are easy to remember, I no longer have to remember these 6 permutations that I will probably forget again within the next hour.

Just like how by using strict, I don't have to remember that undeclared variables are implicitly global.

I do not mind typing a little more if that means that I can forget a lot and get away with it.

Especially since the extra code cannot introduce a bug, but only prevent obscure ones, please let me and the rest of the world type "defined". Perl thinks it is needed too: it adds the test in case you forget it. That's how important perl thinks it is, and I agree with perl. I agree strongly enough to explicitly use that "defined".

I wish everyone continues to use defined. I hope that tutorials and books will continue to preach it, even when it isn't necessary. This is just like "use strict;" in many ways: the extra keystrokes prevent bad things.

I sincerely hope that not too many beginners read your post, and that people who already know Perl well are sane enough to evaluate and then disregard it.

How do you feel about the "return" statement as the last statement in a sub? I like it and use it whenever I can (i.e. when the sub is not an lvalue-sub), even though Perl implicitly returns the last evaluated expression anyway.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

  • Comment on Re: Re: Re: To Kill a Meme: while(defined($line = <>))