in reply to Naming Subs
A dispatch table is a neat way to do that. It is a hash, keyed by your input string, with code references as values.
my %action = ( go => sub { # some code }, turn => \&turn_sub, #... } while (1) { my $act = <>; chomp $act; # parsing can get fancier here exists $action{$act} and $action{$act}->(); }
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Naming Subs
by eoin (Monk) on Jan 12, 2003 at 00:27 UTC |