--- "Stokes, John" <[EMAIL PROTECTED]> wrote:
> I've figured out how to set a cookie, and I think I've retrieved it
> successfully (no errors, at least), but now how do I manipulate it? I can't
> figure out how to reference the cookie data.
> 
> Here's an example of my code:
> 
> use CGI;
> $q = new CGI();
> $myCookie = $q->cookie(-name=>'Fyre',
>                        -value=>test,
>                        -expires=>'+3M',
>                        -domain=>'.biola.edu');
> print $q->header(-cookie=>$myCookie);
> %cook = $q->cookie(-name=>'Fyre'); 

First issue:  you do not appear to be using 'strict'.  I've had to maintain legacy 
code from
people who didn't use it and simple things like finding a misspelled variable name 
which should
have taken 2 seconds would wind up taking half an hour.  'use strict' is incredibly 
important. 
Here's a quick clean-up of that first code section:

#!/usr/bin/perl -wT
use strict;
use CGI;
my $q = CGI->new;

#note that the value of '-value' is now quoted.
my $myCookie = $q->cookie( -name    => 'Fyre',
                           -value   => 'test',
                           -expires => '+3M',
                           -domain  => '.biola.edu');
print $q->header( -cookie => $myCookie );

The second issue:

> %cook = $q->cookie(-name=>'Fyre'); 

Generally, you cannot use CGI's 'cookie' method unless the cookie has been returned.  
That
requires that it be sent to the browser and then the browser issues a request for 
another resource
that accesses that cookie.  That *may* be the same script, but run twice (the first 
run sets it,
the second run retrieves it).

The cookie method will return a scalar representing the '-value' that is stored in the 
cookie:

my $cookie_value = $q->cookie( 'Fyre' );

If any of the above was not clear, send another message and I (or someone else) will 
explain in
more detail.

Cheers,
Curtis

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to