in reply to Problem storing value in persistent hash with MLDBM

It looks like the problem is that you are not updating at the top level, so the TIE interface is not picking up your changes. See the note under the BUGS section of the MLDBM (not MLDBM::Sync) docs. It's a limitation of Perl's TIE interface, and has a simple (albeit not pretty) workaround.
  • Comment on Re: Problem storing value in persistent hash with MLDBM

Replies are listed 'Best First'.
Re: Re: Problem storing value in persistent hash with MLDBM
by relax99 (Monk) on Oct 07, 2002 at 18:50 UTC
    Thank you for your reply. You're right. I also realized that, but only in a while after posting the message. Would you suggest a workaround based on the structure of my code? Should I make %{$sessions} a class variable or something and (try to) detect when something inside it changes? I can't think of a nice workaround for this. Does anyone know of a general solution in this case? It's pretty simple if I use a relational database, but I'm not so sure in the case with Berkeley DB files. Alex
      It's really not an issue of the storage mechanism (dbm vs. RDBMS), just a simple problem with Perl's TIE mechanism. In your case, I would change it so that you always write to $sessions->{$session_id} when you modify anything in the session. For example:
      my $aref = $sessions->{$session_id}; $aref->{timestamp} = time; $sessions->{$session_id} = $aref;

        That's basically what I have done. I have insert_key() method, which updates $session object, but also updates the tied %{$sessions} variable. You can only see and refer to $session object from the main screen, the update of tied hash structure %{$sessions} happens when you call $session->insert_key().