[Chapter 8] 8.40 DB_File
Author: Ellen Siever, Stephen Spainhour & Nathan Patwardhan
Date: 1999-07-02T01:44:46Z

#

| Chapter 8 Standard Modules |

## 8.40 DB_File

Ties a Perl hash to one of the Berkeley DB database types and lets you use functions provided in the DB API:

>     [$X =] tie %hash,  "DB_File", $filename [, $flags, $mode, $DB_HASH];
>     [$X =] tie %hash,  "DB_File", $filename, $flags, $mode, $DB_BTREE;
>     [$X =] tie @array, "DB_File", $filename, $flags, $mode, $DB_RECNO;

The types are:

`$DB_HASH`

  Stores key/data pairs in data files; equivalent to other hashing packages like DBM, NDBM, ODBM, GDBM, and SDBM.

`$DB_BTREE`

  Stores key/data pairs in a binary tree.

`$DB_RECNO`

  Uses a record (line) number to access fixed-length and variable-length flat text files through the same key/value-pair interface as in `$DB_HASH` and `$DB_BTREE`.

After you've `tie`d a hash to a database:

>     $db = tie %hash, "DB_File", "filename";

you can access the Berkeley DB API functions:

>     $db->put($key, $value, R_NOOVERWRITE);  # invoke the DB "put" function

All the functions defined in the dbopen(3) manpage are available except `close` and `dbopen` itself. The constants defined in the dbopen manpage are also available.

Here are the functions available (the comments note only the differences from the equivalent C function):

- del
- fd
- get
- put
- seq
- sync

8.39 Data::Dumper |  | 8.41 Devel::SelfStubber