Hi Punit,
On Mon, 6 Aug 2012 15:30:49 +0530
punit jain <[email protected]> wrote:
> Hi,
>
> I have a program where a subroutine creates a hash. I want to later
> tie it to BerkleyDB.
First of all, one should note that BerkeleyDB can only handle hashes where the
keys and the values are all strings. Otherwise, be aware that I don't think
you can tie a hash after the fact to BerkeleyDB. But one thing you can do
is populate a BerkeleyDB database with the contents of such a hash.
Oterhwise, I would recommend against using most tie-based interfaces, and use
the plain object-oriented interfaces instead. See Perl Best Practices for the
reason.
Regards,
Shlomi Fish
>
> my $users = {};
> my $entry = {};
> my $env = new BerkeleyDB::Env
> -Home => $tmp_dir,
> -Flags => DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL
> or die "cannot open environment: $BerkeleyDB::Error\n";
> my $berkeleydb_temp_file = "/tmp/tmp.berkeleydb";
> my $sdat = searchfunc( $users, $entry ); # sdat is a reference to
> hash of hash of hash
>
> my $db = tie %$sdat, 'BerkeleyDB::Hash',
> -Filename => $berkeleydb_temp_file,
> -Flags => DB_CREATE,
> -Env => $env
> or die "Cannot create file: $! $BerkeleyDB::Error\n";
>
> this doesnot seem to work and I cannot retrieve anything from $db.
>
> Any ideas ?
>
> Regards,
> Punit
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/
Logic sucks. Morality sucks. Reality sucks. Deal with it!
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/