Created
February 9, 2011 07:56
-
-
Save turugina/818122 to your computer and use it in GitHub Desktop.
basic example of BDB::Wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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