I'm pretty new to perl scripting but most of my cgi's at work look like this near the beginning. How is that crazy bit of code better? (Post_only is just a function that returns the function or a 404 if the request isn't a post)
# Dispatcher
my %action = (
'search' => \&controller_search,
'view' => \&controller_view,
'save' => post_only(\&controller_edit),
'delete' => post_only(\&controller_delete),
'index' => \&controller_index,
);
if(exists $action{$q->param('do')}){
$action{$q->param('do')}->();
}else{
$action{'index'}->();
}
exit;