in reply to Storing a Hash inside a CGI::Session Param?
What you are talking about is serializing data ie take a hash, turn it into a string for storage/transport, reconstitute the hash. I tend to use Storable but here are lots of other serialisation options. See FreezeThaw, Data::Serializer, Data::Dumper and friends to name a few.
However CGI::Session will handle serialisation for you (you can select the Module to use for it as well). All you need to do is save a hash_ref, then you can restore a hash ref
use CGI::Session; use Data::Dumper; my %hash = ( foo => 1, bar => 2 ); my $session = new CGI::Session("driver:File", undef, {Directory=>'/tem +p'}); $session->param(-name=>'hash', -value=>\%hash); my $hash_ref = $session->param('hash'); print Dumper $hash_ref,
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Storying a Hash inside a CGI::Session Param?
by Stenyj (Beadle) on Jul 04, 2004 at 01:28 UTC |