Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IO::File

Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.

Provides object-oriented file operations compatible with Perl’s IO::File. IO::File inherits from IO::Handle and IO::Seekable.

All file operations delegate to FILEHANDLE_TABLE via the __fh_id key stored on the blessed hashref object.

Synopsis

use IO::File;
my $fh = IO::File->new("file.txt", "r") or die "Cannot open: $!";
while (my $line = $fh->getline) {
    print $line;
}
$fh->close;
my $out = IO::File->new("> output.txt") or die $!;
$out->print("Hello, World!\n");
$out->close;

Functions

O_APPEND

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_CREAT

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_EXCL

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_NOCTTY

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_NONBLOCK

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_RDONLY

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_RDWR

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_SYNC

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_TRUNC

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

O_WRONLY

POSIX file-open flag constants, re-exported from Fcntl for convenience.

use IO::File;
my $fh = IO::File->new("f", O_RDWR | O_CREAT);

new

Constructor. With no arguments, returns an unopened IO::File object. With a filename, opens the file and returns a blessed handle. Supports both string mode ("<", ">", ">>", "+<") and numeric O_* flags.

use IO::File;
my $fh = IO::File->new();
my $fh = IO::File->new("file.txt");
my $fh = IO::File->new("file.txt", "r");
my $fh = IO::File->new("file.txt", O_RDWR | O_CREAT, 0644);
my $fh = IO::File->new("> output.txt");

Single-argument form parses mode prefixes from the filename (e.g., "< file", "> file", ">> file").

new_tmpfile

Creates a temporary file opened for read/write. The file is immediately unlinked, so it vanishes when the handle is closed.

my $fh = IO::File->new_tmpfile();
$fh->print("temp data");

open

Opens (or re-opens) a file on an existing IO::File object. Supports string modes and numeric O_* flags, like new.

my $fh = IO::File->new();
$fh->open("file.txt", "<") or die $!;