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 );
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.