
The Cookie Technology
create cookies withPerl
#! /usr/bin/perl -w
use CGI
my $q = new CGI;
my $cookie = $q->cookie( -name=>'username',
-value=>"WSB", expires=>'+10m' );
print $q->header( -cookie=>$cookie ),
$q->start_html( 'Perl cookie example' ),
$q->p, "I just sent you a cookie!", $q->p,
$q->end_html;
Notes
-
This example uses the CGI function library to
help create and send a cookie. This approach is simple and less error
prone. This library is included in the standard Perl distribution.
-
However, you may also create all the response
headers yourself. By doing this, you get optimal control over how
the headers look. On the other hand, it's not as easy to maintain
the code as in approach one.