in reply to Mr. Ternary is greater than Mrs. If Else
hi,,, while ago i was wondering why do some programmers rarely uses the ternary operator. wherein it is less typing indeed. i believe in the classic virtue of Perl which is laziness.
I believe in that virtue too. Though the answer is the usual one: we aim for the right™ amount of conciseness, not for maximum one - except in golf that is. The ternary operator is good for what it's good for: simple branching with simple expressions, and returning a value. That it can also be used as a general purpose branching construct is a whole another matter. In particular your use of block eval's (or do's) smells mostly like a dirty hack to me. Moreover, while I often happen to use if conditions, I find that they rarely have an else block too, let alone elseif ones, courtesy of all the early loop, sub and program exit facilities available.
|
|---|