in reply to Re: if statement confusion
in thread if statement confusion
I'm afraid that I would come fairly unglued if I saw such an "economical" attempt to write an if statement in the fewest number of characters. The difference makes absolutely no difference at all to the Perl compiler, but it has the very human difference of being utterly un-maintainable.Ironically, the original code:
is "un-maintainable" not because it is too short but because it is not short enough! Writing it like this:6 < 8 ? $ans = "true" : $ans = "false";
is perfectly clear and, by eliminating the (error-prone) repeated use of $ans, maintainability is improved.$ans = 6 < 8 ? "true" : "false";
Since you suggested an if statement, I certainly hope you're not suggesting replacing it with:
This version has the same dubious violation of of DRY as the original, and so is less "maintainable" than the improved simple ternary version IMHO.if (6 < 8) { $ans = "true"; } else { $ans = "false"; }
|
|---|