in reply to Redirection within a Perl script
The for ($funct) { ... } one-time loop is better written as
but switches are awkward things in perl. They are always a scan over a bunch of conditions. You can only group the most frequent requests first to improve them.{ local $_ = $funct; #... }
Another way, tidier I think, is to build a dispatch table of the coderefs,
Now you can call any action by $action($funct}->() or default(); (for some sub default). I've eliminated the case insensitivity, since the keys ought to be coming from your form.my %action = ( 'Save News' => \&savenews, 'Save Book' => \&addbook, 'Save Observ' => \&addobserv, 'Save Rule' => \&addrule, # ... 'Next' => \&viewbooks, 'Prev' => \&viewbooks, );
Update: runrig++ is wise to suggest checking for existence of the $func key. His trinary op for calling is better than what I showed. I forgot to mention that the CGI::Application module provides a good wrapper for this sort of thing.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Redirection within a Perl script
by bradcathey (Prior) on Dec 04, 2003 at 03:18 UTC |