How might this work?

Andy Armstrong andy at
Mon Feb 26 21:44:36 GMT 2007

On 26 Feb 2007, at 21:24, Dirk Koopman wrote:
> Isn't this just dup()? The problem you have with that is that on  
> non-seekable (or at least non-rewindable) things (like sockets),  
> reading anywhere from it will IIRC consume the data.

No, it's not like dup() for the reason you describe.

While there's more than one handle attached you buffer any input and
give each handle its own position in the buffered data. When the number
of attached handles falls back to one, reads on that handle return
whatever is left in the buffer and then revert to reading directly from
the handle

< unbuffered  ><      buffered        ><  unbuffered
         [ IO::Mark->new ]

You can have multiple IO::Marks active on the handle at any time. They
share a single buffer that starts accumulating data when the first
IO::Mark is created and stops accumulating data when all the IO::Marks
have disappeared and all the data in the buffer has been consumed.

Andy Armstrong,

More information about the mailing list