Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: buffering zipped pipes (Tie::Handle)

by tye (Sage)
on Oct 04, 2016 at 02:38 UTC ( #1173209=note: print w/replies, xml ) Need Help??

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        

  • Comment on Re: buffering zipped pipes (Tie::Handle)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173209]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-09-30 22:36 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.