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.
In reply to RE: cursebox v0.9 - switch{} coding style
by Corion
in thread cursebox v0.9 - "The Cursed Jukebox"
by odie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |