in reply to cursebox v0.9 - "The Cursed Jukebox"
Update: Please use strict; !
Though I have not used this code, I have one comment to make in the spirit of TIMTOWTDI (hopefully a good comment) - I find the simulated switch statement to map a keypress to an action rather clumsy, as it does not really allow to easily add other actions later or add other actions dynamically.
In such situations, I prefer to use a hash of code references, like this :
and the routine interpretplay() would then look like this (sadly, untested) :my %actions = ( "n" => \&skip, "m" => \&movesong, # ... rest ommited ... "\n" => \&goto, );
or, if the whole state machine would be changed to use hashes, one could even use a single interpret() method that would simply look at the $current_state hash reference to find the action to be executed.sub interpretplay { if (exists $actions{$char}) { &$actions{$char}; } else { &invalid; }; };
Dynamically loaded actions would then simply modify the %actions hash with their entry.
|
---|
Replies are listed 'Best First'. | |
---|---|
(jcwren) RE: cursebox v0.9 - switch{} coding style
by jcwren (Prior) on Sep 15, 2000 at 05:57 UTC | |
RE: RE: cursebox v0.9 - switch{} coding style
by odie (Sexton) on Sep 13, 2000 at 23:06 UTC |
In Section
Craft