Update: - fixed screwed-up formatting within code tags.

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:

$result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4 ? 33 : $val == 1 ? 18 : die "not handled") : die "not handled";
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.

Cheers,
Darren :)


In reply to Re^2: nested tabular ternary by McDarren
in thread nested tabular ternary by bowei_99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.