http://qs321.pair.com?node_id=1173209


in reply to buffering zipped pipes

See Tie::Handle and the documentation that it references (mostly perltie).

Using that you can make a handle that hides the real file handle inside of itself. Then you can have your handle's implementation of READLINE squirrel away a copy of the read line to an internal buffer. You'd implement a SEEK that would set an attribute so that the next call to READLINE would read from the hidden buffer.

But mixing byte-offset logic (seek) with read-line logic gets to be a pain. So implementing such a tied handle such that it can take care of all of the general cases may be more work than reworking your code a tiny bit so that you are calling methods and then implementing an object that only supports the functionality you need (read next line, save this line and subsequent lines, go back to the saved line, etc.). That way you could deal only in "lines".

Alternately, you could implement a tied handle that works well enough if you only use it in the ways that your program currently does. So, for example, tell() would give you back a line number not a byte offset and trying to READ instead of READLINE would croak.

- tye