PerlIO::rewindable - I/O layer to allow rewinding of streams
binmode \*STDIN, ":rewindable";
This PerlIO layer makes it possible to rewind an input stream that would otherwise not be rewindable, such as a TTY or a pipe from another process. Reads pass through this layer, reading from the underlying stream, but this layer keeps a copy of everything that is read. seek can be used to move around within the saved data to reread it.
seek
seeks may be relative (whence=1, SEEK_CUR) or absolute (whence=1, SEEK_SET). For the purposes of absolute seeking, position 0 is wherever the stream was when this layer was pushed. tell can be used to read this absolute position. End-relative seeks (whence=2, SEEK_END) are not supported, even if the underlying stream has signalled EOF. If the underlying stream is actually seekable, for example if it is actually a regular file, that aspect of it is hidden by the rewindability layer.
SEEK_CUR
SEEK_SET
tell
SEEK_END
Seeking both backwards and forwards is supported within the saved data that was previously read. Seeking forwards past the last data read from the underlying stream is not currently supported, but this may change in the future.
Writing is not permitted through the rewindability layer.
If this layer is popped, it attempts to maintain any rewound state, by generating a temporary PerlIO layer to hold pending data. This is then subject to normal PerlIO behaviour, which does not strongly maintain consistency of such rewinding.
"ungetc" in IO::Handle, PerlIO, "open" in perlfunc, "seek" in perlfunc
Andrew Main (Zefram) <zefram@fysh.org>
Copyright (C) 2010, 2011, 2017 Andrew Main (Zefram) <zefram@fysh.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install PerlIO::rewindable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PerlIO::rewindable
CPAN shell
perl -MCPAN -e shell install PerlIO::rewindable
For more information on module installation, please visit the detailed CPAN module installation guide.