On Wed, Jun 29, 2005 at 02:25:49PM +0200, demerphq wrote:
> On 6/29/05, Michael G Schwern <[EMAIL PROTECTED]> wrote:
> > On Tue, Jun 28, 2005 at 06:25:31PM -0000, Justin Mason wrote:
> > > However, there is one key difference: "while (<$io>)" and "while
> > > ($io->getline)" ha ve different behaviour.    If the last line of an 
> > > input file
> > > contains "0" (with no trailing newline), "while (<$io>)" will read it and
> > > perform an iteration of the while loop, but "while ($io->getline)" will 
> > > read
> > > it, consider it a false value, and instead break out of the while loop.
> > 
> > Confirmed.  while(<FH>) must have some sort of special case to consider
> > "0" true to avoid this sort of gotcha.
> 
> while (<FH>) {
> 
> is documented to be equivelent to
> 
> while (defined($_=<FH>)) {
> 
> in perlvar I/O Operators.
> 
> 
> 
> -- 
> perl -Mre=debug -e "/just|another|perl|hacker/"
> 

Then, how does the following sound to everyone...

--- ext/IO/lib/IO/Handle.pm.old Sun Apr  4 08:32:35 2004
+++ ext/IO/lib/IO/Handle.pm     Wed Jun 29 08:34:48 2005
@@ -117,7 +117,10 @@

 This works like <$io> described in L<perlop/"I/O Operators">
 except that it's more readable and can be safely called in a
-list context but still returns just one line.
+list context but still returns just one line.  If used within a
+conditional statement, however, you will need to emulate the
+functionality of <$io> with C<defined($x = $io->getline)> where
+C<$x> is a scalar you have previously defined.

 =item $io->getlines


Steve Peters
[EMAIL PROTECTED]

Reply via email to