IO::Seekable(3pm)
π IO::Seekable π
okay so this is the IO::Seekable page from the Perl Programmers Reference Guide (that's the 3pm one, yes bestie, the perl docs) β and it's literally all about teaching your I/O objects how to move around in a file. no cap, this is the seek queen's origin story π
β¨ NAME β¨
IO::Seekable β the module that supplies seek-based methods for I/O objects. that's it, that's the whole vibe. π¦
πΈ SYNOPSIS πΈ
use IO::Seekable;
package IO::Something;
@ISA = qw(IO::Seekable);
like, you don't call it directly β you inherit from it. periodt. π
π DESCRIPTION π
so here's the tea: IO::Seekable does not have a constructor of its own β nope, none, it's not that kind of module. it's intended to be inherited by other IO::Handle based objects. it's giving supporting-character-with-main-character-energy, honestly. π«Ά
what it does do is give you methods that let you seek around the file descriptors. iconic behaviour.
π $io->getpos
returns an opaque value that represents the current position of the IO::File β or undef if that's not possible (eg. an unseekable stream such as a terminal, pipe or socket β yeah, some things just don't wanna be seeked, and that's valid π).
fun implementation detail: if the fgetpos() function is available in your C library, it's used to implement getpos; otherwise perl emulates getpos using C's ftell() function. lowkey clever ngl. β¨
π $io->setpos
uses the value from a previous getpos call to return to a previously visited position β like a little bookmark but make it β¨time travelβ¨.
returns "0 but true" on success, "undef" on failure. yes, "0 but true" is a real string that's true and also zero, and it ate. π₯
so basically, for complete descriptions of each of the following supported IO::Seekable methods, you wanna peek at perlfunc β because these are literally just front ends for the corresponding built-in functions. same energy, new wrapper. π
π $io->seek ( POS, WHENCE )
seeks the IO::File to position POS, relative to WHENCE. here's the WHENCE lore:
WHENCE=0(SEEK_SET) βPOSis absolute position. (seek relative to the start of the file π)WHENCE=1(SEEK_CUR) βPOSis an offset from the current position. (seek relative to current π)WHENCE=2(SEEK_END) βPOSis an offset from the end of the file. (seek relative to end π)
the SEEK_* constants can be imported from the Fcntl module if you don't wish to use the numbers 0 1 or 2 in your code β honestly bestie, use the constants, your future self will thank you π
returns 1 upon success, 0 otherwise.
π $io->sysseek( POS, WHENCE )
similar to $io->seek, but it sets the IO::File's position using the system call lseek(2) directly β so it will confuse most perl IO operators except sysread and syswrite (see perlfunc for full details).
fr fr, this one is a little unhinged: it bypasses the normal buffering, so mixing it with regular IO is asking for chaos π you've been warned, bestie.
returns the new position, or undef on failure. a position of zero is returned as the string "0 but true" β she's back, the icon, the legend. β
π $io->tell
returns the IO::File's current position, or -1 on error. short, sweet, slays. π
π¦ SEE ALSO π¦
perlfunc, "I/O Operators" in perlop, IO::Handle IO::File
(go read them, iykyk π)
π HISTORY π
derived from FileHandle.pm by Graham Barr <gbarr@pobox.com> β thank you for your service, king π«‘
and that's the page, bestie!! β¨ this was the IO::Seekable(3pm) manpage, straight out of the Perl Programmers Reference Guide, from perl v5.42.3, dated 2026-11-03. go forth and seek responsibly πππΈ
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms