Mailing List Archive

Hashes in %udat
Hello list,
I have two embperl Pages, which both alter %udat.
The changes in %udat are only reflected by the page that does the update
when i change/insert hashes to udat. I didn't find anything in the
archive about this.

These are the pages:

page1.ep:
<html>
[*
$udat{'lists'}->{'list1'}->{'key1'} = $fdat{'in'};
print Data:::Dumper::Dumper ( \%udat );
*]
</html>

page2.ep:
<html>
[*
$udat{'lists'}->{'list1'}->{'key2'} = $fdat{'in'};
print Data:::Dumper::Dumper ( \%udat );
*]
</html>

If I first call page1.ep?in=something it prints as expected:
"$VAR1 = {
'lists' => { 'list1' => { 'key1' => 'something' }}

If I then call page2?in=someotherthing it prints:
"$VAR1 = {
'lists' => { 'list1' => { 'key2' => 'someotherthing' }}

so key2 is missing in this %udat.

Repeatedly changing the values is reflected in the respective pages but
they never see the values from the other page.

I found a workaround in changing something in the first Level of %udat.
If I add a $udat{'ptime'} = time() in the pages, than they both see the
other values too. So they both print:

"$VAR1 = {
'lists' => {
'list1' => { 'key1' => 'something',
'key2' => 'someotherthing' }
}
}

Am I missing something
Is this a bug?

regards
frank



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Hashes in %udat [ In reply to ]
> -----Original Message-----
> From: Frank Wesemann [mailto:f.wesemann@fotofinder.net]
> Sent: Thursday, 20 April 2006 8:03 AM
> Subject: Hashes in %udat
[snip]
> Repeatedly changing the values is reflected in the respective
> pages but
> they never see the values from the other page.
>
> I found a workaround in changing something in the first Level
> of %udat.
> If I add a $udat{'ptime'} = time() in the pages, than they
> both see the
> other values too. So they both print:
>
> "$VAR1 = {
> 'lists' => {
> 'list1' => { 'key1' => 'something',
> 'key2' => 'someotherthing' }
> }
> }
>
> Am I missing something
> Is this a bug?

No - its expected behaviour when you know why to expect it :) This is
something that really should
be documented explicitly in the Embperl docs as it catches a few people!

Gerald, any chance of getting a quick sentence to that effect in the
%udat description?
(http://perl.apache.org/embperl/pod/doc/Embperl.-page-5-.htm#sect_15)


Think of it this way: If you do $hash{key1}{key2}++ are you updating any
element of %hash? No, you are updating the hash pointed to by the
reference in $hash{key1}. The reference is still the same so a shallow
check of %hash means no changes are detected.

The most common fix is, as you've already done, to update a timestamp or
simply increment a top-level counter or similar.

%udat is essentially a tied hash via Apache::Session. From the Apache
session docs
(http://search.cpan.org/~cwest/Apache-Session-1.80/Session.pm#BEHAVIOR):

...
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.
...

Hope that explains what you've experienced.



Cheers,

Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org