in reply to Re: Problem storing value in persistent hash with MLDBM
in thread Problem storing value in persistent hash with MLDBM

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
  • Comment on Re: Re: Problem storing value in persistent hash with MLDBM

Replies are listed 'Best First'.
Re: Re: Re: Problem storing value in persistent hash with MLDBM
by perrin (Chancellor) on Oct 07, 2002 at 20:58 UTC
    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().