Basic Cookie Getting/Setting

I have the following two scripts:
#!/usr/bin/perl -w
use CGI qw(:standard);

$usercookie = cookie( -NAME => "foo",
                      -VALUE => "saved_data",
                      -EXPIRES => "+2y" );
print header(-COOKIE => $packed_cookie);

print "Tried to set cookie<BR>\n";  
use CGI qw(:standard);

$data = cookie("foo");

print header();

print "from cookie got $data<BR>\n";    
But when I run setcookie then getcookie, I don't
get the cookie information.  When I close out netscape
the cookie.txt file doesn't show anything either.  
Anything I'm obviously doing wrong here?
obviously wrong?
Who is Participating?
lordvorpConnect With a Mentor Commented:
I'm almost embarrassed to answer this one:
#!/usr/bin/perl -w
use CGI qw(:standard);

$usercookie = cookie( -NAME => "foo",
^^^^^^^^^^^           -VALUE => "saved_data",
                      -EXPIRES => "+2y" );

# establishing a variable called $usercookie

print header(-COOKIE => $packed_cookie);
# uses a previously undefined value for the cookie, which of course has a null response.                              
kisraelAuthor Commented:

Man, I snipped this test code from a slightly more complex script I was starting for clarity, where $usercookie was the name of the cookie (instead of foo) but of course I copied this error right along with it.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.