Andrew Mayo wrote:
> 
> We are trying to store references in session variables but for some reason
> this does not work. The reference cannot be regained.
> 
> For example, in simple Perl I can create an array containing two anonymous
> hashes, then place a reference to this array in
> $d, then dereference $d to recover the array.
> 
> @c[0]={'k1','v1','k2','v2'};
> @c[1]={'k3','v3','k4','v4'};
> $d=\@c;
> print $$d[0]{'k1'},"\n";
> @e=@$d;
> print $e[0]{'k1'},"\n";


The Apache::ASP $Session object is tied to a SDBM_File or DB_File via MLDBM
Data::Dumper.  Therefore you cannot simply store a reference using "\@c" and
expect it to dereference next time.  Use an anonymous array [] or anonymous
hash {}.

Try this:

@c[0]={'k1','v1','k2','v2'};
@c[1]={'k3','v3','k4','v4'};
$Session->{'array'} = [ @c ];
print $Session->{'array'}->[0]->{'k1'},"\n";
@e = @{$Session->{'array'}};
print $e[0]{'k1'},"\n";

DBI handles should be storable also, just be sure to use anonymous hash
syntax, since they are blessed hashes.

- Adi

Reply via email to