# Cookie processing requires a special mention. Cookies are in groups
# of name/value pairs. Each of those groups makes up one cookie to
# the client. Only 1 group can be persistent (kept between sessions). Each
# cookie group looks like "group=k1::v1~k2::v2". There are matching
# Javascript routines to extract cookies from groups.
 
use CGI::Cookies;
 
my $persistentCookies = new CGI::Cookies();
my $cookies = new CGI::Cookies( 'cookieGroupName');
 
# found() is used to see if a cookie exists.
# nextInstance() is used to iterate through the cookies.
if ($cookies->found())
  { do { .... } while ($cookies->nextInstance()); }
 
# get() retrieves cookies and returns undefined if there is none.
# get() can retrieve a list of cookies on demand.
# All keys are case independant (saved as upper case)
my $value = $cookies->get( 'key');
print "Not found" if not defined($value);
 
my ($gross, $nett, $tax) = get $cookies( 'gross', 'nett', 'tax');
 
# makePermanent will make the current cookie group permanent
# so that it can be kept between sessions.
# set() will send this group to the browser. It must be called before
# the page is displayed.
makePermanent $cookies;
set $cookies( key => value1, key2 => value2, ...);
 
# If you need to deal with cookies outside the system (no groups),
# use the RawCookie methods. The getAllRawCookies method
# is used if a cookie has more than one value - which happens if
# it is set by different levels of the URL structure.
my $value = CGI::getRawCookies( 'key');
CGI::setRawCookie( key => $value);
my @cookies = getAllRawCookies();