Question : How can I use cookies to store a numeric count

How can I use a cookie in CGI to keep track of a hit count.  I attatched my code below but its not working.  
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
#!/usr/bin/perl
#c11ex5.cgi - displays a Web page containing the user's
#name and the book information
use CGI qw(:standard);
 
#prevent Perl from creating undeclared variables
use strict;
 
#declare variables
my ($count, $C_name);
 
if (!cookie('Count')){
print "Hello";
}
 
 
#assign input to variable
#$count = cookie('Count');
#$count = $count + 1;
 
 
#create cookie
$C_name = cookie(-name => "Count",
                 -value => "$count",
                 -expires => "6M");
 
 
#send cookie to browser
 
#create Web page
print "\n";
print "Jubilee Book Club\n";
print "\n";
print "

Hello!
\n"; print "You have been here $cookie('count') times.

\n"; print "\n";
Open in New Window Select All

Answer : How can I use cookies to store a numeric count

#!/usr/bin/perl
#c11ex5.cgi - displays a Web page containing the user's
#name and the book information
use CGI qw(:standard);
 
#prevent Perl from creating undeclared variables
use strict;
 
#declare variables
my ($count, $C_name);
 
 
#assign input to variable
$count = cookie('Count');
$count = $count + 1;
 
 
#create cookie
$C_name = cookie(-name => "Count",
                 -value => "$count",
                 -expires => "6M");
 
print header(-type=>'text/html',
             -cookie=>$C_name,
);
 
if (!cookie('Count')){
print "Hello";
}else{
 
#send cookie to browser
 
#create Web page
print "\n";
print "Jubilee Book Club\n";
print "\n";
print "

Hello!
\n";
print "You have been here $count times.

\n";
print "\n"
}
Random Solutions  
 
programming4us programming4us