Next | Tricks of the Wizards | 73 |
sub READLINE { my ($self) = @_; readdir($self->{DH}); }
Or perhaps you would prefer that <$dh> returns an object representing the directory entry:
sub READLINE { my ($self) = @_; my $file = readdir($self->{DH}); my $fullname = "$self->{DIRNAME}/$file"; my @statinfo = stat($fullname); return unless @statinfo; return Dir::Statinfo->new(FULLNAME => $fullname, BASENAME => $file, STATINFO => \@statinfo); }
And then use it like this:
while (<$dh>) { print $_->fullname, " is a ", $_->filetype;
print " containing ", $_->size, " bytes" if $_->filetype eq 'plain file';
print " linking to ", $_->readlink if $_->filetype eq 'symbolic link';
print "\n"; }
Next | Copyright © 2003 M. J. Dominus |