I'm trying to pass a tied hash using BerkeleyDB to a subroutine and modifying the contents of the database in the routine, but it's not working.
#!/usr/bin/perl
use warnings;
use strict;
use BerkeleyDB;
sub testdb($)
{
my $dbptr = shift;
my %db = %{$dbptr};
print("inside foo: ", $db{'foo'}, "\n");
$db{'biz'} = "baz";
return 0;
}
my %database;
my $dbhand = tie %database, 'BerkeleyDB::Hash', -Filename => "test.db";
print "outside foo: ", $database{'foo'}, "\n";
testdb(\%database);
print "returned: ", $database{'biz'}, "\n";
$dbhand->db_close();
undef($dbhand);
untie %database;
exit(0);
But when I run it:
./dbtie
outside foo: foobar
inside foo: foobar
Use of uninitialized value in print at ./dbtie line 24.
returned:
So it appears that I can read from the database, but I cannot write to it. Why?
I tried doing a db_sync() at the end of the subroutine, but it made no difference.
This is Perl 5.14 using BerkeleyDB version 0.54. It is in turn using Berkeley DB version 6, creating a version 9 hashtable.