On Fri, Mar 22, 2002 at 09:37:05AM -0500, David Gray wrote:
> while(<STDIN>) will create an infinite loop,
No, it won't. The "while (<FILEHANDLE>)" idiom will read one line at a
time and automatically terminate the loop at the end of the file.
> so you do need some sort of
> sentinel value to break out of the loop if you encounter it in the user
> input. For example, you could do:
>
> while(<STDIN>) {
> last if /^\-1/;
> print
> }
This will prematurely terminate the while loop. Perhaps that's what you
want, but it isn't required.
> Which terminates the loop when the user enters -1 at the beginning of a
> line. Or you could read from a file which would make it easier to test
> for the end of input.
That's a very non-obvious and befuddling interface. Entering ^D
(or possibly ^Z on Win*) sends an EOF to standard in put, which
will cause the loop to terminate.
This allows STDIN to work properly when reading from the console as well
as when reading a file passed as standard input.
Z.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]