
japhy
Enthusiast
Aug 30, 2000, 4:19 AM
Post #2 of 2
(287 views)
|
|
Re: Calling subroutines to parse forms
[In reply to]
|
Can't Post
|
|
You can't just send a parameter to a CGI program and expect it to run a function of that name for you. Oddly enough, this question came up in the CIWAC (comp.infosystems.www.authoring.cgi) newsgroup, and I had an answer for it. If you call your program as http://www.server.com/program.cgi?FUNCNAME, then the following subroutine will execute the given function (if it exists). <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # dispatch(CONTINUE) # CONTINUE - boolean determining whether to # continue running the program after the # function has been called sub dispatch { my $continue = shift; my $func = $ENV{QUERY_STRING}; my $glob = *$func; $glob->() if defined &$glob; exit unless $continue; } </pre><HR></BLOCKQUOTE> This function is used like so: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl dispatch($x); # where $x is true or false # your program here... sub dispatch { # the dispatch function here... } </pre><HR></BLOCKQUOTE> Note that dispatch() makes no effort to URL-decode the query string. Should that be needed, you can do that yourself. ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|