[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] <> warning



On Tue, Jul 28, 1998 at 10:07:16AM -0400, William B. Birkett wrote:
} When I run a program containing the following lines,
} 
}     while ($line = <IN_FILE>) {
}         print $line;
}     }
} 
} I get the following warning,
} 
} # Value of <HANDLE> construct can be "0"; test with defined().
} File 'Untitled'; Line 10
} 
} The reason I am using $line is that I have another file opened and don't
} want to alter the $_ variable. This construct is in the MacPerl P&E book,
} so I assume it is commonly used.

It's a warning about the following possibility.  Suppose you have a
file with a single 0 on a line by itself (I'm not sure whether a
trailing \n "fixes" the problem or not).  Then, since the string "0"
is false, the loop will stop at that point.  This may not be what you
had in mind.

This seems to have been fixed in 5.005.  I just tried to invoke the
warning (I'm running LinuxPPC at the moment, with Perl 5.005
installed) and I can't make it happen.  The warning doesn't occur when
the code is parsed, and I can't get it to stop with a "0" on a line,
with or without a trailing newline.

} 
} The program executes properly, but I am bothered by the warning. What does
} the warning mean? Is there a better way to write this code?

while(defined($line = <IN_FILE>))

since end-of-file is denoted by undef.

} 
} 
} William B. Birkett
} Precision Color, Inc.
} 9200 General Drive
} Plymouth, MI 48170 (USA)
} 
} Phone: (734) 459-5640
} FAX:   (734) 459-4210
} 

---
Paul Schinder
schinder@pobox.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch