Skip to content

Instantly share code, notes, and snippets.

@turugina
Created February 9, 2011 07:56
Show Gist options
  • Save turugina/818122 to your computer and use it in GitHub Desktop.
Save turugina/818122 to your computer and use it in GitHub Desktop.
basic example of BDB::Wrapper
use strict;
use warnings;
use BDB::Wrapper;
my $dbfile = '/path/to/file.bdb';
my $wrap = BDB::Wrapper->new;
if ( my $h = $wrap->create_write_dbh($dbfile) ) {
local @SIG{qw/INT TERM QUIT/};
$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub { $h->db_close; };
my $ret = $h->db_put(key => 'value')
$h->db_close;
if ( $ret == 0 ) {
print "db_put success.\n";
}
else {
die "failed to put";
}
}
if ( my $h = $wrap->create_read_dbh($dbfile) ) {
my $value;
my $ret = $dbh->db_get(key => $value);
$dbh->db_close;
if ( $ret == 0 ) {
print "db_get success. key => $value\n";
}
else {
die "failed to get";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment