Bare Bones Cookies
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);

%info = cookie("data");

if (param("Save Form"))
{
    $info{'name'}     = param('name');
    $info{'address'}  = param('address');
    $info{'email'}    = param('email');
    $cookie = cookie(-name => "data", -value => \%info, -expires => '+1y'); 
#  The header statement below tells the browser to deliver this cookie
#  to the browser in future transactions with my script.  NECESSARY!! 
    print header(-cookie => $cookie),
          start_html,
          p(strong("See you later!")),
          end_html;
}
elsif (param("Submit Form"))
{
    $cookie = cookie(-name => "data", -value => \%info, -expires => '-1d');
#  Cookie cleared.  Tell browser NOT to deliver this cookie in future
#  transactions with my script!  NECESSARY!!
    print_form($cookie, \%info);
}
elsif (!param())
{
#   %Info is defined if a cookie exists (I have visited before).
#   Header in print_form does NOT say what to do with cookie, hence undef.
#   "Submit Form" and "Save Form" have that responsibility!
    print_form(undef, \%info);
}


sub print_form
{
   my ($cookie, $info) = @_;

#  Header issues cookie cancellation message if cookie is defined.
   print $cookie ? header(-cookie => $cookie): header;
   print start_html,
         start_form,
         p("Name: "),
         textfield(-name => 'name', -value => $info->{'name'},
                   -override => 1),
         p("Address: "),
         textfield(-name => 'address', -value => $info->{'address'},
                  -override=>1),
         p("Email: "),
         textfield(-name => 'email', -value => $info->{'email'},
                   -override => 1),
         submit(-name => "Save Form"),
         submit(-name => "Submit Form"),
         reset,
         end_form,
         end_html;
}