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.  
#!/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 "<HTML>\n";
print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=center>Hello!<BR>\n";
print "You have been here $cookie('count') times.</H1>\n";
print "</BODY></HTML>\n";

Open in new window

monica73174Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/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 "<HTML>\n";
print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=center>Hello!<BR>\n";
print "You have been here $count times.</H1>\n";
print "</BODY></HTML>\n"
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.