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

Hi all: I've got the following code set to delete some cookie's in Fgiure #1, yet when I run the code in Figure #2, I still get the old values? Any ideas. Figure #1
#!/usr/bin/perl5 use CGI qw/:standard/; use CGI::Cookie; my $c3 = new CGI::Cookie(-name => 'preferences', -value => '', -expires => 'now', -domain => '', -path => '/' -secure => 0 ); my $c1 = new CGI::Cookie(-name => 'ID', -value => '', -expires => 'now', -domain => '', -path => '/' -secure => 0 ); my $c2 = new CGI::Cookie(-name => 'userid', -value => '', -expires => 'now', -domain => '', -path => '/' -secure => 0 ); print "Content-Type: text/html\n\n"; print "Set-Cookie: $c1,$c2,$c3\n";
Figure #2
#!/usr/bin/perl5 use CGI qw/:standard/; use CGI::Cookie; %cookies = fetch CGI::Cookie; print "Content-Type: text/html\n\n"; print $ENV{HTTP_COOKIE};

Replies are listed 'Best First'.
Re: CGI::Cookie
by thpfft (Chaplain) on Jul 18, 2002 at 14:35 UTC

    if the $c's were strings, you would just need to swap these round:

    print "Content-Type: text/html\n\n"; print "Set-Cookie: $c1,$c2,$c3\n";

    And break the Set-Cookie into three separate lines of one cookie, with a single \n on the end of each one.

    (The two \n's signify the end of the header, so the Set-Cookie isn't being obeyed. it's presumably appearing on the page.)

    But your $c1, $c2 etc are objects and will just print memory-address gibberish in this form. You need to use CGI.pm's header method: it'll send them right, and take care of those minor formatting issues too.

    update: OEMike is right and i am a fule. CGI::Cookies are string context overloaded (?terminology) and will print nicely the way he called them. and they can be concatenated after all, but with a semicolon, not a comma as he had it. sorry bout that. must.... read... docs...

      Thank you so much, I've been looking for this for about 3 hours! I had finally switched to the Header function, but the CGI::Cookie page shows the Print $c option as a way of doing it --