Re: Saving data to %session with Apache::Session::File

[email protected] ("Brian J. Miller") Tue, 30 Mar 2010 22:21:20 -0400
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
Fabian Gut wrote:
> Hi
> 
> I'm using Apache::Session::File for session management. I have a hash in 
> $session{'config'} that saves some config values.
> 
> I have a script that should change these config values:
> 
> foreach ( sort keys %newconfig ) {
>     $session{'config'}{$_} = $newconfig{$_};
> }
> 
> this works perfectly for the script. However, the values are not written 
> to the session file. Thus they are not stored permanently and if I 
> reload the script, the old values are in $session again. Does anyone 
> know, what might be the reason for that?
> 
> Greetings
> Fabian Gut
> 

 From the Apache::Session docs:

"Note that Apache::Session does only a shallow check to see if anything 
has changed. If nothing changes in the top level tied hash, the data 
will not be updated in the backing store. You are encouraged to 
timestamp the session hash so that it is sure to be updated."

So in your loop you are updating the nested structure under 'config' but 
nothing at the top level of the hash. To have it stored you would have 
to update a key or value of $session.

HTH,

-- 
Brian J. Miller
End Point Corp.
http://www.endpoint.com/
[email protected]