IO::File#
Native implementation of IO::File
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#
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 $!;
O_RDONLY / O_WRONLY / O_RDWR / O_CREAT / O_EXCL / O_TRUNC / O_APPEND / O_NONBLOCK / O_NOCTTY / 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);