Just an observation regards style. (And please don't get me wrong - this is just an observation, not a critisism - each to their own :)
I find it interesting that both yours and Liverpole's answer use a similar layout style for the ternary. That is - to break the line after an operator.
This of course goes against what is recommended by TheDamian in PBP (pp. 27-29 & 121-123). Personally, I prefer his recommended style, and I would have written your second example like so:
To me, this is more readable - it looks more like a "table", and it's more obvious that there is some nesting. Also, having an operator at the start of a line makes it much more obvious that it's a continuation of the previous line.$result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4 ? 33 : $val == 1 ? 18 : die "not handled") : die "not handled";
Cheers,
Darren :)
In reply to Re^2: nested tabular ternary
by McDarren
in thread nested tabular ternary
by bowei_99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |