DirHandle(3p) Perl Programmers Reference Guide DirHandle(3p)

DirHandle(3p) Perl Programmers Reference Guide DirHandle(3p) #

DirHandle(3p) Perl Programmers Reference Guide DirHandle(3p)

NNAAMMEE #

 DirHandle - (obsolete) supply object methods for directory handles

SSYYNNOOPPSSIISS #

     # recommended approach since Perl 5.6: do not use DirHandle
     if (opendir my $d, '.') {
         while (readdir $d) { something($_); }
         rewind $d;
         while (readdir $d) { something_else($_); }
     }

     # how you would use this module if you were going to
     use DirHandle;
     if (my $d = DirHandle->new(".")) {
         while (defined($_ = $d->read)) { something($_); }
         $d->rewind;
         while (defined($_ = $d->read)) { something_else($_); }
     }

DDEESSCCRRIIPPTTIIOONN #

 TThheerree iiss nnoo rreeaassoonn ttoo uussee tthhiiss mmoodduullee nnoowwaaddaayyss..

 The "DirHandle" method provide an alternative interface to the ooppeennddiirr(()),
 cclloosseeddiirr(()), rreeaaddddiirr(()), and rreewwiinnddddiirr(()) functions.

 Up to Perl 5.5, ooppeennddiirr(()) 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 ooppeennddiirr(()).  Since Perl
 5.6, ooppeennddiirr(()) alone has been all you need for lexical handles.

perl v5.36.3 2019-02-13 DirHandle(3p)