First of all use the CGI module, it'll make your life easier
in general, not just dealing with cookies.
use strict;
use CGI qw(:standard);
$q = new CGI;
# Create a 11 character random string as a
# session id. (Yes, it's swiped from the perl cookbook:-)
@chars = ( "A" .. "Z", "a" .. "z", 0 .. 9 );
$usersession = join("", @chars[ map { rand @chars } (1 .. 11) ]);
# Set a cookie that expires when
# the user closes their browser
$initcookie = $q->cookie(
-name=>'User_Session',
-value=>$usersession,
-expires=>'', # leave this blank
-path=>'/',
-domain=>'www.somewebsite.com',
-secure=>0
);
print $q->header(-cookie=>$initcookie);
For more info on the CGI module, go to:
http://stein.cshl.org/~lstein/
Shawn