Next Tricks of the Wizards 73

Tied Filehandles

        sub READLINE {
          my ($self) = @_;
          readdir($self->{DH});
        }
        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);
        }
        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