ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
3.2.24 dbmopendbmopen This binds a DBM file to a hash (that is, an associative array).
(DBM stands for Data Base Management, and consists of a set of C library
routines that allow random access to records via a hashing algorithm.)
Values assigned to the hash prior to the dbmopen are not accessible. If you don't have write access to the DBM file, you can only read the hash variables, not set them. If you want to test whether you can write, either use file tests or try setting a dummy array entry inside an eval, which will trap the error. Note that functions such as keys and values may return huge list values when used on large DBM files. You may prefer to use the each function to iterate over large DBM files. This example prints out the mail aliases on a system using sendmail: dbmopen %ALIASES, "/etc/aliases", 0666 or die "Can't open aliases: $!\n"; while (($key,$val) = each %ALIASES) { print $key, ' = ', $val, "\n"; } dbmclose %ALIASES; Hashes bound to DBM files have the same limitations as DBM
files, in particular the restrictions on how much you can put into a
bucket. If you stick to short keys and values, it's rarely a problem.
Another thing you should bear in mind is that many existing DBM
databases contain null-terminated keys and values because they were
set up with C programs in mind. The B News history file
and the old sendmail aliases file are examples. Just use
There is currently no built-in way to lock generic DBM files. Some would consider this a bug. The DB_File module does provide locking at the granularity of the entire file, however. See the documentation on that module in Chapter 7 for details. This function is actually just a call to tie with the proper arguments, but is provided for backward compatibility with older versions of Perl. |