Question

I am using a DBM::Deep hash object like so:

my $dbm = DBM::Deep->new(
        file      => "dbm.db",
        locking   => 1,
        autoflush => 1,
        type      => "DBM::Deep->TYPE_HASH",
        );
#code..
$dbm = $hash_reference;

However, this doesn't work. $dbm holds the correct values during the program, but after it exits dbm.db is empty and when I start up another program that tries to use dbm.db, there's nothing in it. But whenever I copy the hash reference like this (it's a two level deep hash):

    for my $id (keys %$hash_reference) {
        for(keys %{$hash_reference->{$id}}) {
            $todo->{$id}->{$_} = $hash_reference->{$id}->{$_};
        }
    }

Then it will copy everything over correctly and the values will still be there after program execution. The DBM author seems to stress though that his DBM::Deep objects work just like a regular hash, so does anyone know if there is an easier way to do this? Thanks!

Was it helpful?

Solution

You’re throwing away the object. Try this instead:

%$dbm = %$hash_reference;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top