| Next | Tricks of the Wizards | 32 |
package IO::Flushable;
sub new {
my ($package, $mode, $filename) = @_;
open my $fh, $mode, $filename or return;
bless $fh => $package;
}
People can use this object just like a filehandle:
my $fh = IO::flushable->new(">", "logfile") or die ...;
print $fh "Blah blah blah\n";
syswrite $fh, $logentry;
close $fh;
It also closes automatically when it is destroyed.
| Next | ![]() |
Copyright © 2003 M. J. Dominus |