Next | The Perl Hardware Store | DC.pm Version | 49 |
package IO::Remembers; sub new { my ($pack, $filename) = @_; my $fh = \do { local *FH }; # Incantation open $fh, $filename or return; bless $fh => $pack; }
People can use this object just like a filehandle:
my $fh = IO::Remembers->new('inputfile'); my $line = <$fh>; read $fh, $bytes, 1024; print $fh "Actually this filehandle is open for reading only...\n"; close $fh;
It also closes automatically when it is destroyed.
Next | Copyright © 2003 M. J. Dominus |