Q&A

Q1:How do I put more than one thing in an HTTP cookie?
A1: The easiest way is to combine multiple items in a single cookie separated by a field separator, as in this example:
$cookie=cookie(-name => 'preferences',
    -value => 'bgcolor=blue,fgcolor=red,banners=no,java=no');

Later, when you retrieve the cookie, you can use split to separate the items:

    $cookie=cookie('preferences');
    @options=split(/,/,  $cookie);
# Now, make a hash with the option as the key,
# and the option's value as the hash value
foreach $option (@options) {
    ($key,$value)=split(/=/, $option)
    $Options{$key}=$value;
}
Q2:How do I use cookies to track which links a user clicks on a Web page?
A2: Before I give you the answer, you must realize that some people consider tracking ...

Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.