in reply to Flow control / case structure
my %actions = ( Register => \&handle_register, "Book Course"=> \&handle_book_course, # ... ); # ... if (defined $actions{$action}) { $actions{$action}->(); } else { print "No such action $action..."; }
Basically you have a hash giving a subref for each action. You can even write an anonymous subroutine in the dispatch table using the sub { ... code here ... } syntax. This should be pretty fast and allow you to easily add or remove actions, and have one action be callable by multiple names.
Note that calling a subroutine named by the action argument is a major security risk if you don't at least run checks to see if it's valid first.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Flow control / case structure
by demerphq (Chancellor) on Sep 08, 2001 at 02:53 UTC |