Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
the structure of the script
Hmm. You seem to do
  1. read the list of questions in
  2. print the first question
  3. read the list of answers
  4. print the first answer
Now, how would you go for a random question, considering that there can be multiple answers for a question?
  1. read the list of questions in - ok
  2. print a random question - ok
  3. read the list of answers - ok
  4. print … which answer???
Better control flow would be:
  1. read the list of questionss and answers, preserving the relation between q and a
  2. select a random q&a group
  3. print the selected question
  4. 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

In reply to Re^4: How could I create a command line quiz? by soonix
in thread How could I create a command line quiz? by yasser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-07-04 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?