Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

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 such as 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 tied 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.

The following are the functions available (the comments note only the differences from the equivalent C function).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page