home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

12.3 Directory Handles

UNIX and POSIX programmers are used to reading directories and their contents using a system library function called readdir . As it turns out, this function is what Perl uses to provide directory access. Perl implements readdir (and its companions) using a new type of object called directory handles . A directory handle is a name from yet another namespace, and the cautions and recommendations that apply to filehandles also apply to directory handles (you can't use a reserved word, and uppercase is recommended). The filehandle FRED and the directory handle FRED are unrelated.

The directory handle represents a connection to a particular directory. Rather than reading data (as from a filehandle), you use the directory handle to read a list of filenames within the directory. Directory handles are always opened read only; you cannot use a directory handle to change the name of a file or to delete a file.