Going Off the Beaten DB Path (cont'd)
Taking Berkeley to Task
Let's take a look at how you can get started with Berkeley DB. I'm assuming you've already downloaded the package from the Sleepycat Web site and installed it on your preferred platform, and that you have Perl 5 installed. I'll provide code examples here using Perl, on the grounds that it's free, simple, and available for a variety of platforms. Access to Berkeley DB using Perl comes courtesy of one of two modules: BerkeleyDB, which is currently still in alpha stage, and DB_File, which is stable. DB_File comes with the standard Perl 5 distribution, so chances are you've already got it, but it never hurts to check.
The following code creates a Berkeley DB file and adds some data to it.
#!/usr/local/bin/perl
use strict;
use DB_File;
my %hash;
tie %hash, "DB_File", "myDB"
or die "Could not create file 'myDB': $!\n";
$hash{'key1'} = 'value1';
$hash{'key2'} = 'value2';
$hash{'key3'} = 'value3';
untie %hash;