How might this work?

Andy Armstrong andy at hexten.net
Wed Feb 28 02:51:15 GMT 2007


> I'd like to implement a module that permits this:
>
> use IO::Mark;
>
> sub examine {
>     # Get the file handle. Might not be seekable
>     my $fh = shift;
>
>     my $mark = IO::Mark->new($fh);
>
>     my $buf;
>     $mark->read($buf, 1000, 0);
>
>     # Do something with buf
>
>     # On exit $fh rewinds making the fact that we've read from it
>     # invisible
> }
>
> IO::Mark is a clone of a filehandle that you can read from without
> (apparently) consuming input from the underlying handle.

It's here if anyone's interested:

http://search.cpan.org/~andya/IO-Mark-v0.0.1/lib/IO/Mark.pm

Not entirely happy with the implementation but as a proof of concept  
it seems to work.

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list