Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Answer: Subroutine accessible as yourdomain.com/cgi-bin/foo.pl?foo

( #38762=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > Subroutine accessible as yourdomain.com/cgi-bin/foo.pl?foo contributed by chromatic

Jellybean is based on this idea.

The easiest thing to do is to create a hash of code refs. Pull out the query string or URL information or whatever, then use that data as the hash key.

If there's a valid code ref there, call that subroutine. If not, show an error or do a default sub.

For example, you could write:

my %sub_refs = ( foo => \&do_this, bar => \&do_that, ); my $request = $ENV{QUERY_STRING}; if (defined(my $action = $sub_refs{$request})) { $action->(); } else { default(); }
I'd do something more sophisticated in place of the query string scheme, as it's not terribly brilliant.

Comment on Answer: Subroutine accessible as yourdomain.com/cgi-bin/foo.pl?foo
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-03 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls