FileHandle class
Syntax
my $fh = new FileHandle(name, mode);
name | The filename for the accessed file. |
mode | How the file is accessed including r for read and w for
write. |
The FileHandle class manages input and output operations for files.
When the object is scavenged, the file is closed.
Example
my @lines;
my $fh = new FileHandle("filename.txt", "r");
if (defined $fh) {
@lines = $fh->getlines();
undef $fh;
}
The example opens a text file, reads all of the lines from the file
into an array, and closes the file.
autoflush variable
Syntax
$fh->autoflush = expression;
expression | 0 to flush output only on request, 1 to flush output after every
write. |
print subroutine
Syntax
$fh->print(string, ...);
string | One or more strings for printing to the file. |
printf subroutine
Syntax
$fh->printf(format, string, ...);
format | A string with tokens for interpolating and formatting strings. |
string | One or more strings to interpolate. |
getline subroutine
Syntax
$fh->getline;
getlines subroutine
Syntax
$fh->getlines;