the structure of the script
Hmm. You seem to do
- read the list of questions in
- print the first question
- read the list of answers
- print the first answer
Now, how would you go for a random question, considering that there can be multiple answers for a question?
- read the list of questions in - ok
- print a random question - ok
- read the list of answers - ok
- print … which answer???
Better control flow would be:
- read the list of questionss and answers, preserving the relation between q and a
- select a random q&a group
- print the selected question
- print the corresponding answers
Problem: you need a structure, yes, but not only of the script (control flow) but also for your data (be that arrays or objects). That might be possible with bash and grep, but that will be very specific and therefore difficult to translate to any other language, including Perl
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|