Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Reducing the complexity of dispatch tables

by ikegami (Patriarch)
on Aug 31, 2007 at 15:15 UTC ( [id://636354]=note: print w/replies, xml ) Need Help??


in reply to Reducing the complexity of dispatch tables

You could just refer to the same sub more than once:
my %dispatch = ( home => \&default, donate => \&default, news => \&default, samp => sub { \&samples($dbh) }, ... ); $action = $apr->param('a'); $action = 'home' if !exists $dispatch{$action}; $dispatch{$action}->($action); sub default { my ($action, $params) = @_; return render_template($action, $params); } sub samples { my ($action, $dbh) = shift; ... }

Shortcut:

my %dispatch = ( (map { $_ => \&default } qw( home donate news )), samp => sub { \&samples($dbh) }, ... );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found