Rex::FS::File(3pm)
π Rex::FS::File(3pm) π
okay bestie, pull up a chair, we're reading a Perl manpage and it's gonna be cute. this is Rex::FS::File, from the User Contributed Perl Documentation section, and it's literally just called File Class. iconic behavior tbh. β¨
πΈ NAME πΈ
Rex::FS::File β it's a File Class. that's it, that's the name, she's simple and she knows it π
π¦ DESCRIPTION π¦
so like, this is the</**> File Class that gets used by file_write and file_read. that's the whole description bestie, she's not doing a TED talk about it. it's the file class those two functions lean on, no cap. π«Ά
β¨ SYNOPSIS β¨
here's the vibe, code and all, verbatim because we do not mess with code in this house:
use Rex::Interface::File;
my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );
my $file = Rex::FS::File->new(fh => $fh);
$file->read($len);
$file->read_all;
$file->write($buf);
$file->close;
look at her go. create a file interface, pop it open, wrap it in a Rex::FS::File, and then read/write/close to your heart's content. main character energy fr fr. π
π CLASS METHODS π
π new
this is the constructor, the birthing suite, the origin story. you have two options and you must pick one:
- hand her a filehandle that the object should work on, or
- hand her a filename.
little warning bestie: if you go the filehandle route, it has to be a Rex::Interface::File::* object. not just any old filehandle, okay? she's picky. π
filehandle first, here's how:
my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );
my $file = Rex::FS::File->new(fh => $fh);
and now the filename route, because sometimes you just wanna say the name and go:
# open a local file in read mode
my $file = Rex::FS::File->new(
filename => 'filename',
mode => 'r', # or '<'
type => 'Local',
);
# or shorter
my $file = Rex::FS::File->new( filename => 'filename' );
# open a local file in write mode
my $file = Rex::FS::File->new(
filename => 'filename',
mode => 'w', # or '>'
);
look how short that second one is. she said "less is more" and honestly? she ate. π₯
Allowed modes: here's the menu, memorize it:
< read
r read
> write
w write
>> append
a append
and for the allowed types? those live over in the documentation of Rex::Interface::File β go read that one, bestie, she's got the list. π
π write($buf)
writes $buf straight into the filehandle. just shove your string in there and she'll take it from here.
$file->write("Hello World");
π§ seek($offset)
seeks to the file position $offset. think of it as teleporting the little cursor wherever you want her to be. β¨
so like, to set the file pointer to the 5th byte:
$file->seek(5);
boom. teleported. π¦
π read($len)
reads $len bytes out of the filehandle. you tell her how many bytes, she brings you back exactly that many. an icon.
my $content = $file->read(1024);
β read_all
reads everything out of the filehandle. the whole thing. no crumbs left. she is thorough and she is obsessed with getting the full picture.
my $content = $file->read_all;
πΈ close
closes the file. say goodbye, shut the door, turn off the lights. πͺ
$file->close;
π SEE ALSO π
ngl there's no SEE ALSO section in this one bestie β the only reference she name-drops is Rex::Interface::File (for the allowed types), so go bother that page next. π
okay that's the whole page, you made it, so proud of you π₯Ήπ
this little masterpiece is from perl v5.40.1, dated 2025-10-03, and it lives in the User Contributed Perl Documentation corner of the world. no notes. slay. π β¨π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms