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
In reply to Re: Redirection within a Perl script
by Zaxo
in thread Redirection within a Perl script
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |