Jeff Pang [mailto:[EMAIL PROTECTED] wrote:

> use MLDBM qw(DB_File Storable);

> the primary problem is this statement:  delete $records{$mid}->{$time};
> the action of 'delete' don't take effect.
> and I try to write it as following:
> 
>     my $tmp = $records{$mid}; delete $tmp->{$time};
> 
> but the bad result is the same as before.
> 
> why this happen and how to resolve it?thanks really.

This is the way MLDBM works.  Only the top-level hash is tied, so only
changes to the top-level hash are written to the DBM.

For example:

tie %h, 'MLDBM', 'mydbm', ...;

$h{'animals'} = { dog => 1 };
$h{'animals'}{'cat'} = 1;

mydbm will contain { animals => { dog => 1 } }.  The 'cat' assignment was
not made at the top-level of the hash, so the tie mechanism doesn't even see
it.

Instead, to assign cat later, you would have to do something like this:

tie %h, 'MLDBM', 'mydbm', ...;

$h{'animals'} = { dog => 1 };
$tmp = $h{'animals'};
$tmp->{'cat'} = 1;
$h{'animals'} = $tmp;

Now mydbm will contain { animals => { dog => 1, cat => 1 } }.


Similarly, in order to delete from the nested hash:

$tmp = $h{'animals'};
delete $tmp->{'cat'};
$h{'animals'} = $tmp;


This all makes sense when you think of it in terms of how tie works.


HTH,
Ronald


Reply via email to