Tie::DirHandle - definitions for tied directory handles
use Tie::DirHandle; [$ref =] tie *FH, "Tie::DirHandle", *DH, "/usr/local/lib"; while (<FH>){ do_something_with_file($_); } (tied *FH)->rewind; # or $ref->rewind; untie *FH;
This module provides filehandle-like read access to directory handles. There are not many available methods, because directory handles are read-only. The only methods are TIEHANDLE, READLINE, DESTROY, and rewind.
TIEHANDLE
READLINE
DESTROY
rewind
To tie a filehandle to a directory handle, the syntax is as follows: tie *FILEHANDLE, "Tie::DirHandle", *DIRHANDLE, "/path/to/dir";
The module will open the directory (and croak with an error if not able to do so). When untying the filehandle, the directory is closed.
After a filehandle has been tied to a directory handle, you can read from the directory using the <HANDLE> syntax. This syntax calls READLINE.
To rewind the directory, there are two possible syntaxes: (tied *FH)->rewind; or $ref->rewind;
The second works if you have stored the return value of the tie in a variable $ref. The value of tied *FH and $ref are the same.
tied *FH
The variable $ref (or tied *FH) contains a hash reference, with three keys. $ref->{HANDLE} returns the directory handle it references. $ref->{PATH} and $ref->{DIR} are synonymous, and return the path of the directory.
This ties the specified directory handle to the filehandle given as the first argument to tie(). DIR is the pathname of the directory.
This returns the next value (if called in a scalar context) or the next values (if returned in a list context) of readdir().
This closes the directory.
Look into perltie, the documentation on the tie() function.
Jeff Pinyan (CPAN ID: PINYAN) jeffp@crusoe.net www.crusoe.net/~jeffp
To install Tie::DirHandle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::DirHandle
CPAN shell
perl -MCPAN -e shell install Tie::DirHandle
For more information on module installation, please visit the detailed CPAN module installation guide.