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

Re: [MacPerl] print while (chop($_=<F>));



Xah Lee writes:
|Suppose I have a file with consecutive returns, and in my script I have this
|line
|print $_ while (chop($_=<F>));
|I'm expecting the printing of the file to terminate when the consecutive
|returns are read, but apparently it's not the case.

The loop will terminate when chop returns '', '0', or undef:

- Chop returns '' when given an empty string or undef, which will only
  occur in this case at the end of the file.
- Chop returns '0' when '0' is the last character on the line, which can
  only happen when the last line in the file contains just '0' with no
  newline.
- As far as I can tell, chop never returns undef.

Therefore I'd expect the loop to terminate at end of file or when the
last line of the file is '0' with no newline. Are you seeing something
different?

Brian

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