NAME
Tie::TextDir - interface to directory of files
SYNOPSIS
use Tie::TextDir;
tie (%hash, 'Tie::TextDir', '/some_directory', 'rw'); # Open in read/write mode
$hash{'one'} = "some text"; # Creates file /some_directory/one
# with contents "some text"
untie %hash;
tie (%hash, 'Tie::TextDir', '/etc'); # Defaults to read-only mode
print $hash{'passwd'}; # Prints contents of /etc/passwd
DESCRIPTION
This is the Tie::TextDir module. It is a TIEHASH interface which lets you tie a Perl hash to a directory of textfiles.
To use it, tie a hash to a directory:
tie (%hash, "/some_directory", 'rw'); # Open in read/write mode
If you pass 'rw' as the third parameter, you'll be in read/write mode, and any changes you make to the hash will create or modify files in the given directory. If you don't open in read/write mode you'll be in read-only mode, and any changes you make to the hash won't have any effect in the given directory.
LIMITATIONS
You may not use the empty string, '.', or '..' as a key in a hash, because they would all cause integrity problems in the directory.
This has only been tested on the UNIX platform, and some of the shadier techniques probably won't work right on MacOS or DOS.
CAUTIONS
Strange characters can cause problems when used as the keys in a hash. For instance, if you accidentally store '../../f' as a key, you'll probably mess something up. If you knew what you were doing, you're probably okay. I'd like to add an optional (by default on) "safe" mode that URL-encodes keys (I've lost the name of the person who suggested this, but thanks!).
AUTHOR
Ken Williams (ken@forum.swarthmore.edu)
SEE ALSO
perl(1).