But there is no string manipulation nor checking in his second solution; whereas the first you are advocating does have string checking. String manipulation isn't exactly hideous either; a lot work has been put into making Perl blazing fast for that kind of task. (Number crunching on the other hand is hideous indeed.)
In other efficiency notes, remember that even though the name of the method in $obj->method() is known at compile time, Perl still has to look it up at run time. This is exactly the same amount of work as $obj->$anymethod() takes, so the if elsif route has to do as much work as the simpler method in addition to the string comparisons.
Note also that the best optimization method for Perl scripts is to try to offload as much work as possible into builtins. The if elsif does a lot of work in the script itself.
Lastly, I'd argue against the if elsif route simply because it makes for far harder to maintain code. The data driven method frees programmer time I can spend on getting more code written and/or bugfixed.
Makeshifts last the longest.
In reply to Re^2: input switch
by Aristotle
in thread input switch
by well
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |