IO::Seekable#

Native implementation of IO::Seekable

Provides seek/tell operations on filehandles compatible with Perl’s IO::Seekable. IO::Seekable is a mixin class inherited by IO::File and others. All methods delegate to FILEHANDLE_TABLE via the shared extract_fh_id() helper.

Functions#

seek#

Sets the filehandle position. $whence is one of SEEK_SET (0), SEEK_CUR (1), or SEEK_END (2). Returns 1 on success, 0 on failure.

use IO::Seekable;
$fh->seek(0, SEEK_SET);

tell#

Returns the current byte position in the filehandle, or -1 on error.

my $pos = $fh->tell();

setpos#

Sets the filehandle position to an absolute byte offset (equivalent to seek($pos, SEEK_SET)). Returns 1 on success, 0 on failure.

$fh->setpos($saved_pos);

getpos#

Returns the current byte position, equivalent to tell(). Intended for use with setpos() to save and restore positions.

my $pos = $fh->getpos();
# ... read some data ...
$fh->setpos($pos);

SEEK_SET / SEEK_CUR / SEEK_END#

Seek position constants (0, 1, 2). Exported both as constant subs and package scalars.