#!/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; }