Looking at just this part of your code:
# this gives $result as 1, not 33. Makes sense, # since $val == 4 evaluates to 1. But, I want $result to # be assigned 33, based on the fact that $val == 4. $result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4) : 33;
If I understand what you're asking for, you want:
if ($major_length == 4800) { $result = 18; } elsif ($major_length == 8552) { if ($val == 4) { $result = 33; } else { # $result is Unspecified (see A below) } } else { # $result is Unspecified (see B below) }
You can do this with nested ternaries (though it's a little messy), but if you only want to use ternaries, you'll have to specify what to set $result to if none of the conditions is met (eg. $result = undef):
$result = ($major_length == 4800)? 18: (($major_length == 8552)? (($val == 4)? 33: undef): # see A above undef); # see B above
But it's messy as I said, and unless you really want to set $result to some value, it's probably better to use conditionals (eg. if...else), both for your clarity and the clarity of those who may read your code in the future ;-)

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: nested tabular ternary by liverpole
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.