(You are Anonymous)

Added | Removed | Changed | Unmodified

Revision 2 Current
#!E:/Perl/bin/perl.exe   #!E:/Perl/bin/perl.exe  
#   #  
#########################   #########################  
## Author: Sopan Shewale   ## Author: Sopan Shewale  
### This script is created for giving demo on click count.   ### This script is created for giving demo on click count.  
## The Script is support to display increse/decrease click's, handles back button of browser, does not handle reload stuff.   ## The Script is support to display increse/decrease click's, handles back button of browser, does not handle reload stuff.  
## also it's based on sessions.   ## also it's based on sessions.  
########################   ########################  
   
use strict;   use strict;  
use warnings;   use warnings;  
   
use CGI;   use CGI;  
use CGI::Session;   use CGI::Session;  
use CGI::Cookie;   use CGI::Cookie;  
   
my $q = new CGI();   my $q = new CGI();  
my $sessionid = $q->cookie("CGISESSID") || undef;   my $sessionid = $q->cookie("CGISESSID") || undef;  
my $session = new CGI::Session(undef, $sessionid, {Directory=>'/tmp'});   my $session = new CGI::Session(undef, $sessionid, {Directory=>'/tmp'});  
$sessionid = $session->id();   $sessionid = $session->id();  
my $cookie = new CGI::Cookie(-name=>'CGISESSID', -value=>$sessionid, -path=>"/");   my $cookie = new CGI::Cookie(-name=>'CGISESSID', -value=>$sessionid, -path=>"/");  
print $q->header('text/html', -cookie=>$cookie);   print $q->header('text/html', -cookie=>$cookie);  
   
print $q->start_html("Welcome to Click Count Demo");   print $q->start_html("Welcome to Click Count Demo");  
print "<h1>Welcome to Click Count Demo</h1>";   print "<h1>Welcome to Click Count Demo</h1>";  
   
   
my $count = $session->param('count'); ## count-is click count variable   my $count = $session->param('count'); ## count-is click count variable  
if(!defined($count)) { $session->param('count', 0); $count=0;} ### if session is first time created, set count=0   if(!defined($count)) { $session->param('count', 0); $count=0;} ### if session is first time created, set count=0  
   
   
$session->param('count', $count);   $session->param('count', $count);  
$count = $session->param('count');   $count = $session->param('count');  
#print "<h1>The Click Count is: $count \n";   #print "<h1>The Click Count is: $count \n";  
   
## Form stuff   ## Form stuff  
print $q->startform(-method=>'POST');   print $q->startform(-method=>'POST');  
print $q->submit( -name=>"Increase", -value=>'Increase1');   print $q->submit( -name=>"Increase", -value=>'Increase1');  
print $q->submit( -name=>"Decrease", -value=>'Decrease1');   print $q->submit( -name=>"Decrease", -value=>'Decrease1');  
print $q->endform();   print $q->endform();  
   
   
   
## Which button is being pressed   ## Which button is being pressed  
my $which_button = $q->param('Increase');   my $which_button = $q->param('Increase');  
if(defined ($which_button)) {   if(defined ($which_button)) {  
print "Increase pressed";   print "Increase pressed";  
$count = increase_count($count); ## Increase the count since increase button is clicked   $count = increase_count($count); ## Increase the count since increase button is clicked  
$session->param('count', $count);   $session->param('count', $count);  
}else {   }else {  
$which_button=$q->param('Decrease');   $which_button=$q->param('Decrease');  
if(defined($which_button)){   if(defined($which_button)){  
print "Decrease pressed";   print "Decrease pressed";  
$count = decrease_count($count); ## Decrease the count since decrease button is clicked   $count = decrease_count($count); ## Decrease the count since decrease button is clicked  
$session->param('count', $count);   $session->param('count', $count);  
}   }  
else {print "You have not pressed any button, seems you are typing/re-typing the same URL"; } }   else {print "You have not pressed any button, seems you are typing/re-typing the same URL"; } }  
   
$count = $session->param('count');   $count = $session->param('count');  
print "<h1>The Click Count is: $count \n";   print "<h1>The Click Count is: $count \n";  
   
print $q->end_html();   print $q->end_html();  
   
   
## increases the count by 1   ## increases the count by 1  
sub increase_count {   sub increase_count {  
my $number = shift;   my $number = shift;  
$number = $number +1;   $number = $number +1;  
return $number;   return $number;  
}   }  
   
## decreases the count by 1   ## decreases the count by 1  
sub decrease_count {   sub decrease_count {  
my $number = shift;   my $number = shift;  
$number = $number -1;   $number = $number -1;  
return $number;   return $number;  
   
}   }  
   
  Sopan, I reformatted your above code, so it looks like code on the Wiki.
  But what does this have to do with CGI::Application?? -- Mark Rajcok