good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
RE: cursebox v0.9 - switch{} coding styleby Corion (Patriarch) |
on Sep 13, 2000 at 22:47 UTC ( [id://32316]=note: print w/replies, xml ) | Need Help?? |
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) : 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. Dynamically loaded actions would then simply modify the %actions hash with their entry.
In Section
Craft
|
|