#!/opt/bin/perl -Tw ## # Modified from # Figure 27.36 from _Internet & World Wide Web: How To Program_ # by H.M. Deitel, P.J. Deitel, and T.R. Nieto # Published by Prentice Hall, (c) 2000 by Prentice-Hall, Inc. ## # Fig. 27.36: read_cookies.pl # Program to read cookies from the client's computer use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; use diagnostics; use strict; $| = 1; print header; print ""; print ""; print "The folowing data is saved in a cookie on your "; print "computer.

"; my %cookie = readCookies(); print ""; my $cookie_name; foreach $cookie_name (keys %cookie) { print ""; print " "; print " "; print ""; } print "
$cookie_name$cookie{$cookie_name}
"; print '

[return to the form]

'; sub readCookies { my @cookie_values = split(/; /, $ENV{'HTTP_COOKIE'}); my %cookies = (); foreach (@cookie_values) { my ($cookie_name, $cookie_value) = split ( /=/, $_ ); $cookies{$cookie_name} = $cookie_value; } return %cookies; }