package FileHandle;
-use 5.003_11;
+use 5.006;
use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
+our($VERSION, @ISA, @EXPORT, @EXPORT_OK);
-$VERSION = "2.00";
+$VERSION = "2.01";
require IO::File;
@ISA = qw(IO::File);
sub import {
my $pkg = shift;
my $callpkg = caller;
- Exporter::export $pkg, $callpkg, @_;
+ require Exporter;
+ Exporter::export($pkg, $callpkg, @_);
#
# If the Fcntl extension is available,
#
eval {
require Fcntl;
- Exporter::export 'Fcntl', $callpkg;
+ Exporter::export('Fcntl', $callpkg);
};
}
use FileHandle;
- $fh = new FileHandle;
- if ($fh->open "< file") {
+ $fh = FileHandle->new;
+ if ($fh->open("< file")) {
print <$fh>;
$fh->close;
}
- $fh = new FileHandle "> FOO";
+ $fh = FileHandle->new("> FOO");
if (defined $fh) {
print $fh "bar\n";
$fh->close;
}
- $fh = new FileHandle "file", "r";
+ $fh = FileHandle->new("file", "r");
if (defined $fh) {
print <$fh>;
undef $fh; # automatically closes the file
}
- $fh = new FileHandle "file", O_WRONLY|O_APPEND;
+ $fh = FileHandle->new("file", O_WRONLY|O_APPEND);
if (defined $fh) {
print $fh "corge\n";
undef $fh; # automatically closes the file
Furthermore, for doing normal I/O you might need these:
-=over
+=over 4
=item $fh->print
=item $fh->getline
This works like <$fh> described in L<perlop/"I/O Operators">
-except that it's more readable and can be safely called in an
-array context but still returns just one line.
+except that it's more readable and can be safely called in a
+list context but still returns just one line.
=item $fh->getlines
-This works like <$fh> when called in an array context to
+This works like <$fh> when called in a list context to
read all the remaining lines in a file, except that it's more readable.
It will also croak() if accidentally called in a scalar context.
=back
+There are many other functions available since FileHandle is descended
+from IO::File, IO::Seekable, and IO::Handle. Please see those
+respective pages for documentation on more functions.
+
=head1 SEE ALSO
The B<IO> extension,