DirHandle(3pm)

πŸ’– NAME πŸ’–

okay so bestie, this is the DirHandle(3pm) page from the Perl Programmers Reference Guide ✨. Short version: DirHandle is the obsolete module that supplies object methods for directory handles. It’s giving retired icon, ngl πŸ’….

🌸 SYNOPSIS 🌸

Here’s the whole vibe. First up, the recommended approach since Perl 5.6: literally do not use DirHandle πŸ™ˆ.

# 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($_); }
}

πŸ¦‹ DESCRIPTION πŸ¦‹

🫠 real talk: there is no reason to use this module nowadays.

The DirHandle method gives you an alternative interface to the opendir(), closedir(), readdir(), and rewinddir() functions. cute concept, but the plot has moved on πŸ’€.

So here’s the lore πŸŽ€: 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(). iconic for its era, lowkey.

But since Perl 5.6, opendir() alone has been all you need for lexical handles. slay for progress ✨.


mwah πŸ’‹ final sign-off, bestie: this page is from perl v5.42.3, dated 2026-11-03, and the manual tag is DirHandle(3pm) πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from