Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm making a simple survey site and using the CGI::Cookie module to store the user information through the course of the survey. The information includes an array. This seems like it should be a simple problem, but for the life of me I can't figure it out.
Essentially, I'm storing one cookie, whose value is a hash containing the user ID number and a reference to the necessary array. The problem arises when the script is called again and I attempt to access the array through the cookie. The array ref only exists now as a string i.e. "ARRAY(0x87480c)". Thus, when I try to access elements in the array, I get the error:
"Can't use string ("ARRAY(0x87480c)") as an ARRAY ref while "strict refs" in use"
Does anyone know why the array itself isn't being saved? My code is based directly on the CGI::Cookie tutorial page...This is the code that initializes the cookie
my $porder = gen_order(30); my $c = $cgi->cookie(-name=>'info',-value=>{ 'user' => $UID, 'porder' => $porder, 'count' => 1 }); print $session->header(-cookie=>$c); sub gen_order { my $limit = shift; my @nums = (1..$limit); fisher_yates_shuffle(\@nums); return \@nums; }
And here is the code that tries to retrieve the array
my %info = $cgi->cookie('info'); my $porder = $info{'porder'}; my $current = $porder->[0];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI cookie turns array ref into string
by zwon (Abbot) on Apr 24, 2010 at 20:40 UTC | |
|
Re: CGI cookie turns array ref into string
by Corion (Patriarch) on Apr 24, 2010 at 20:41 UTC | |
|
Re: CGI cookie turns array ref into string
by dsheroh (Monsignor) on Apr 25, 2010 at 12:46 UTC | |
|
Re: CGI cookie turns array ref into string
by Anonymous Monk on Apr 24, 2010 at 20:29 UTC | |
by dsheroh (Monsignor) on Apr 25, 2010 at 12:51 UTC |