For one thing, a hash with 20 keys is not really very big at all. Another thing is you shouldn't be iterating on the hash keys and matching with eq. The hash can do near O(1) lookups by itself -- that's one of the major reasons to use a hash. You are completely eliminating that advantage, and you're making the code much more complicated than it needs to be. The entire inside of your while loop can be replaced with this:
chomp; if (exists $myhash{$_}) { $myhash{$_}->(); } else { $myhash{default}->(); }
Update: in case it wasn't clear from my reply, I suggest you stick with the hash-based approach. It should work fine for this kind of thing.
In reply to Re: CLI using hashes
by revdiablo
in thread CLI using hashes
by bahadur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |