So I've written the following working example where I call my script via Javascript with a query parameter ( function= ) , the value of function is evaluated by the perl script, and then calls the appropriate sub based on the value. Then I take the output and just display it with some ajax. This all works great with straight perl, however falls apart when I use pperl.
When using pperl the variables do not 're-declare' so if you send 'function=one' to the script 5 times, and then send 'function=two' 5 times, you'll still get the 'funcOne' sub to run. I think I understand why this is I just can't figure a way around. I've looked at mod_perl's, speedyCGI and other persistent environment documentation. Any help would be appreciated.
#!/usr/bin/pperl
use strict;
use CGI qw(:standard);
use Switch;
######################################
# Setup our Variables
my $myCGI = new CGI;
my $parameters = $myCGI->Vars;
# Holds the POST passed function name
my $function = $parameters->{'function'};
######################################
# This is the function request handler, it takes the 'function' argume
+nt passed
# in the POST and calls the correct function
switch ( $function ) {
case 'one' {
print $myCGI->header(-type=>"text/html",-charset=>"UTF-8");
print $myCGI->start_html;
funcOne();
}
case 'two' {
print $myCGI->header(-type=>"text/html",-charset=>"UTF-8");
print $myCGI->start_html;
funcTwo();
}
case 'three' {
print $myCGI->header(-type=>"text/html",-charset=>"UTF-8");
print $myCGI->start_html;
funcThree();
}
else {
print $myCGI->header(-type=>"text/html",-charset=>"UTF-8");
print $myCGI->start_html;
print "Function not found";
}
}
sub funcOne(){
print "\nONE\n";
return( 1 );
}
sub funcTwo(){
print "\nTWO\n";
return( 1 );
}
sub funcThree(){
print "\nTHREE\n";
return( 1 );
}