Приглашаем посетить
Программирование (prog.find-info.ru)

[Chapter 7] 7.2.11 DirHandle - Supply Object Methods for Directory Handles

PreviousChapter 7
The Standard Perl Library
Next
 

7.2.11 DirHandle - Supply Object Methods for Directory Handles

use DirHandle;

my $d = new DirHandle ".";   # open the current directory
if (defined $d) {
    while (defined($_ = $d->read)) { something($_); }
    $d->rewind;
    while (defined($_ = $d->read)) { something_else($_); }
}

DirHandle provides an alternative interface to Perl's opendir, closedir, readdir, and rewinddir functions.

The only objective benefit to using DirHandle is that it avoids name-space pollution by creating anonymous globs to hold directory handles. Well, and it also closes the DirHandle automatically when the last reference goes out of scope. But since most people only keep a directory handle open long enough to slurp in all the filenames, this is of dubious value. But hey, it's object-oriented.


PreviousHomeNext
7.2.10 diagnostics - Force Verbose Warning DiagnosticsBook Index7.2.12 DynaLoader - Automatic Dynamic Loading of Perl Modules