Perl 5 version documentation

DirHandle

NAME

DirHandle - (obsolete) supply object methods for directory handles

SYNOPSIS

  1. # recommended approach since Perl 5.6: do not use DirHandle
  2. if (opendir my $d, '.') {
  3. while (readdir $d) { something($_); }
  4. rewind $d;
  5. while (readdir $d) { something_else($_); }
  6. }
  7. # how you would use this module if you were going to
  8. use DirHandle;
  9. if (my $d = DirHandle->new(".")) {
  10. while (defined($_ = $d->read)) { something($_); }
  11. $d->rewind;
  12. while (defined($_ = $d->read)) { something_else($_); }
  13. }

DESCRIPTION

There is no reason to use this module nowadays.

The DirHandle method provide an alternative interface to the opendir(), closedir(), readdir(), and rewinddir() functions.

Up to Perl 5.5, opendir() could not autovivify a directory handle from undef, so using a lexical handle required using a function from Symbol to create an anonymous glob, which took a separate step. DirHandle encapsulates this, which allowed cleaner code than opendir(). Since Perl 5.6, opendir() alone has been all you need for lexical handles.