Let me try to give you some ideas ...

It seems that you want your program to do at least 4 things:

  1. Create a quiz,
  2. store it some where
  3. let someone take a stored quiz, and
  4. display the results
so make up a parameter (probably hidden) that gets passed to your CGI program that tells it what action you intend. Maybe even call that parameter "action". Then the main part of your program could look something like this:

#!/usr/bin/perl use CGI qw(:standard); my $action = param('action'); $action ||= 'TakeQuiz'; if ($action eq 'CreateQuiz') { CreateQuiz(); } elsif ($action eq 'StoreQuiz' ) { StoreQuiz(); } elsif ($action eq 'ShowResults') { ShowResults(); } else { TakeQuiz(); } # default action exit;

CreateQuiz() would present the user with a form that allows them to enter questions and answers (much the same as the code you currently have). A hidden action parameter on this form would have a value of "StoreQuiz" so that the StoreQuiz() routine can be called when you submit the form. StoreQuiz() would put the results in a file or a database or something for retrieval later. When you want to take the quiz, don't provide an action parameter and let it execute the default TakeQuiz() routine. This routine would read from where ever you stored the questions and answers and display the questions for the user to answer. A hidden parameter named "action" would be set to 'ShowResults' so that when they submitted the form, it would execut the ShowResults() routine. The ShowResults() routine would read from where ever you have the questions and answers stored, read the form data that was submitted, and produce a report that shows the user's answers and the correct answers.

That's a rough design outline (primitive but workable). Now as far as implementing this stuff, just read the documentation for the CGI module. It's got nifty routines for saving form data to and retrieving it from files. And obviously it's got routines for reading the form data submitted by the user.


In reply to Re: Simple Quiz Maker (yet again) by duff
in thread Simple Quiz Maker (yet again) by Anonymous Monk

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.