32.11. DB_Fileuse DB_File; Tie a hash to a DBM-style file:
Tie a hash to a B-tree file, but still access as a regular DBM hash:
Tie an array to a plain text file:
The DB_File module provides tied access to Berkeley
DB.[1] The default tie function
gives you a standard DBM-style database with some features that no
other DBM library provides: there are no size limits on either keys or
values, and your data is stored in a byte-order independent format.
The second tie mechanism uses B-trees to give you a true ISAM (indexed sequential access method) file, that is, a hash whose keys are automatically ordered--alphabetically by default, but configurable by the user. The third tie mechanism binds an array to a file of records (text lines by default) so that changes to the array are automatically reflected on disk. This simulates random access by line number on a regular text file. The standard interface conforms to version 1.x of Berkeley DB; if you want to make use of the new features available in Berkeley DB 2.x or 3.x, use the CPAN module BerkeleyDB instead. Starting with version 2.x, Berkeley DB has internal support for locking; earlier versions did not. See the section "File Locking" in Chapter 16, "Interprocess Communication" for a description of how you can safely lock any kind of database file using flock on a semaphore file. ![]() Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|