in reply to How to 'peek' at next line while parsing with <>

You cannot in general. With non-seekable handles (pipes, STDIN, sockets, fifo, etc) you can't seek back, and usually you can't put something back in the stream either.

But you can use a buffer. The simplest is a one-scalar buffer. If you want to look, read in the line in a scalar, later, if you want to process the line, process the scalar. You can wrap this up in a module, and if you want to be fancy, you tie it to a filehandle. Or with perl 5.8, you should be able to write an IO layer that does that for you.

Abigail

  • Comment on Re: How to 'peek' at next line while parsing with <>