in reply to A rotten cookie

Probably not up to merlyn's standards (lack of use strict for example), but her's something that works.

First time you run it as a cgi, it gives you a form to fill in. After you fill in and and submit, it comes back with "Your cookie is". If you look at your browser's cookies at this point, you'll see it. The third time you run it, it prints as above, but this time because it saw the cookie come back, the value you originally entered shows up.

#!/usr/bin/perl -Tw use CGI; use CGI::Cookie; my $q = CGI->new(); if ( $q->cookie('id') ) # cookie sent back by browser { print $q->header(-cookie=>$q->cookie('id')), $q->start_html, $q->h1('your cookie is ' . $q->cookie('id' +)), $q->end_html; } elsif ( $q->param('name') ) # form filled in by user { $c = CGI::Cookie->new(-name=>'id', -value=>$q->param('name') ); print $q->header(-cookie=>$c), $q->start_html, $q->h1('your cookie is ' . $q->cookie('id')), $q->end_html; } else # no cookie, nor form filled in { print $q->header(), $q->start_html, $q->start_form, "What's your name? ", $q->textfield('name'), $q->submit, $ +q->end_form, $q->end_html; }

--Bob Niederman, http://bob-n.com