Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Answer: Subroutine accessible as

by chromatic (Archbishop)
on Oct 27, 2000 at 05:53 UTC ( #38762=categorized answer: print w/replies, xml ) Need Help??

Q&A > subroutines > Subroutine accessible as - Answer 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
  • Download Code
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2016-12-09 22:23 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (158 votes). Check out past polls.