Personally, I would put all the questions in a separate text file (or in the __DATA__ section of the Perl file, if you like to keep it in one file). Use a record separator of your choice and set $/ accordingly to read them one by one. This way, you'd have to write the code for presenting the questions, getting the reply, etc. only once (at least for a certain type of question, like multiple choice), instead of literally spelling out dozens of prints and ifs...

To indicate correct/incorrect choices, you might want to use different capitalisation (e.g. a. ... for incorrect, A. ... for correct), or indentation, that you extract out of the question text, but remove prior to presenting the question. That might make it easier than having/parsing a separate entry per question which indicates what's correct (just a suggestion...)

Storing the questions in an easily (human-)readable form would also have the added benefit that you can much more easily manage the set of questions in case of additions or updates.


In reply to Re: Best code approach for this goal by almut
in thread Best code approach for this goal by irvson

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.