Reading the code, I think you would benefit from given/when instead of a cascade of elsif statements.
But... maybe you should make a hash as a keyboard mapping. This will not only make your loop simple as all the logic is elsewhere, but allow you to remap the keyboard.
That is, the gathering is centralized, and separate from the code dispatched to. The $key is passed as an argument in case you have common subs for several keys and need to distinguish between them.my $key = ReadKey(-1); next unless defined $key; #next or return depending on your code stru +cture if ($key eq "\e") { #expecting more $key .= ReadKey(-1); # should be a '[' $key .= ReadKey(-1); } my $callback= $keymap{$key}; if (defined $callback) { $callback->($key); } else { beep(); } #no such key is meaningful here
—John
In reply to Re: Most efficient design
by John M. Dlugosz
in thread Most efficient design
by cdlaforc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |