Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

When I try to retrieve my cookie it comes back as a number. How do I
extract the info that I put into my $value (of Set-Cookie: $name=$value etc)?
I have multiple fields that I need to retrieve, so I assigned a hash to $value.
I've looked all over the place but all I get for retrieving stuff is:

%testing = $query->cookie(-name=>$name);

Am I not picking up the right info? What?

Thanks in advance,
t

Replies are listed 'Best First'.
Re: Retrieving Cookies
by ColtsFoot (Chaplain) on Aug 05, 2000 at 14:30 UTC
    The following snippet was lifted from the ActivePerl Docs and
    should answer your question
    use CGI qw/:standard/; use CGI::Cookie; # Create new cookies and send them $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456); $cookie2 = new CGI::Cookie(-name=>'preferences', -value=>{ font => Helvetica, size => 12 } ); print header(-cookie=>[$cookie1,$cookie2]); # fetch existing cookies %cookies = fetch CGI::Cookie; $id = $cookies{'ID'}->value; # create cookies returned from an external source %cookies = parse CGI::Cookie($ENV{COOKIE});
    Hope this is of help
Re: Retrieving Cookies
by maverick (Curate) on Aug 05, 2000 at 19:03 UTC
    $query->cookie returns a scalar, not a hash. I'm not sure if the scalar it returns is a value or a refrence to a hash. But a quick scan of the docs leads me to belive it's the latter (it's early here and I'm not really awake yet). In which case you can access it's attributes like
    my $value = $cookie->{-value}; my $expires = $cookie->{-expires};
    Hope this helps...

    /\/\averick

RE: Retrieving Cookies
by steveAZ98 (Monk) on Aug 05, 2000 at 22:18 UTC
    For each $name in your cookie use:
    $value = $query->cookie($name);
    That should get you the values. HTH
Re: Retrieving Cookies
by Anonymous Monk on Aug 06, 2000 at 00:23 UTC
    Thanks a lot folks! I'll try that out after the weekend...

    t