> Does anyone know if I should be able to write a cookie like : > > <snip> > $secure{USER}=$user->{USER_ID}; > $secure{LEVEL}=$REQUEST{LEVEL}; > %{$secure{USER_CATEGORIES}}=%USER_CATEGORIES; > %{$secure{USER_ACCOUNTS}}=%USER_ACCOUNTS; > @[EMAIL PROTECTED]; > my $my_cookie = $q->cookie(-name=>'TechDirect', -value=>\%secure, > -expires=>'+10h'); > print $q->header({-type=>"text/html", -target=>'toolbar', > -cookie=>$my_cookie}); > </snip> > > When I return the cookie I don't appear to have the USER_CATEGORIES & > USER_ACCOUNTS plus USER_GROUP is null but is an array reference... > The scalar values return OK... >
You need to learn to write little test programs to See What's Really Happening BEFORE you ask the list. .......................... BEGIN PERL PROGRAM .......................... #!/usr/bin/perl use strict; use warnings; use CGI; use Data::Dumper; my %secure; $secure{USER} = 123; $secure{LEVEL} = 'exulted'; %{$secure{USER_CATEGORIES}} = ( metal => 'rusty', fruit => 'citrus' ); @{$secure{USER_GROUPS}} = ( 10, 20, 30 ); warn Dumper \%secure; my $query = new CGI; my $cookie = $query->cookie (-name => 'cookie', -value => \%secure ); warn Dumper $cookie; warn $cookie->as_string; ........................... END PERL PROGRAM ........................... Produces the output (interspersed with commentary) lawrence /tmp > perl test.pl $VAR1 = { 'USER_CATEGORIES' => { 'fruit' => 'citrus', 'metal' => 'rusty' }, 'LEVEL' => 'exulted', 'USER_GROUPS' => [ 10, 20, 30 ], 'USER' => 123 }; Okay -- here we see the secure hashref -- looks good. $VAR1 = bless( { 'value' => [ 'USER_CATEGORIES', { 'fruit' => 'citrus', 'metal' => 'rusty' }, 'LEVEL', 'exulted', 'USER_GROUPS', [ 10, 20, 30 ], 'USER', 123 ], 'name' => 'cookie', 'path' => '/' }, 'CGI::Cookie' ); And, it got promoted into a cookie pretty well ... cookie=USER_CATEGORIES&HASH%280x12afe8%29&LEVEL&exulted&USER_GROUPS&ARRAY%280x21d24c%29&USER&123; path=/ at test.pl line 25. Ahhh, but here we see where it's failing (and by the way, John Paton is right: You Just Can't Do That) Basically: A cookie can have as it's value either a scalar, or a single list of scalars. (Which you can choose to pass in as a listref or a hashref, keeping in mind the relationship bewteen hash constructors and lists ) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>