“The possible letters are: O, B, A, F, G, K and M (in order of ascension).” What happened to R and N?
The easiest code I can think of is to map the designation to a scalar, and then use ordinary numeric ranges to compare.
$answer =~ tr/OBAFGKM/1234567/;
if ($answer >= 56 && $answer <= 59) ...
Spanning letters is not an issue.
Now, you have a lot of the same code but just changing the ranges. Make it into a table, like so:
@results= ( undef, #index 0 unused
[ #describe question 1
qw/ g0 k5 g6 g9/ ],
# another row for each question.
This lists the half-right range, then the full-right range. The code can extract these 4 values, convert them to numbers, test for full-right first (being a subset), then the larger half-right range, all with one block of code.
—John
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.