in reply to CLI using hashes
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CLI using hashes
by bahadur (Sexton) on May 30, 2005 at 01:33 UTC | |
by Anonymous Monk on May 30, 2005 at 02:45 UTC | |
by bahadur (Sexton) on May 30, 2005 at 02:54 UTC | |
by fishbot_v2 (Chaplain) on May 30, 2005 at 03:22 UTC | |
by revdiablo (Prior) on May 30, 2005 at 05:37 UTC | |
by bahadur (Sexton) on May 30, 2005 at 05:59 UTC | |
|