I think the problem here is you haven't really laid out all the possible scenarios. Let's try doing this in English and we'll see where we get:
- If $major_length is 4800, return 18
- Otherwise, If $major_length is 8552:
- If $val is 4, return 33
- If $val is 1, return 18
- Otherwise, ?????
- Otherwise, ?????
You haven't addressed the possibility that (major_length is neither 4800 nor 8852) nor that (major_length is 8852 but val is neither 1 nor 4). Now, it may be that in your application these scenarios are impossible, but the ?: operator does not allow you to simple ignore them. You may find it easier to use an if-else construct instead:
if ($major_length == 4800) {
$result = 18;
} elsif ($major_length == 8552) {
if ($val == 4) {
$result = 33;
} elsif ($val == 1) {
$result = 18;
}
}
You still have the possibility of those unhandled situations, but now they'll simply result in $result not getting assigned at all.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.