Simple Multiple-Choice Question Perl Script


This page describes mcsimple.cgi, which is a PERL script that generates HTML pages containing a multiple-choice question or responses to the user's input. This script was written and developed in Perl 5.0 and is designed to work with Perl 4.0 or greater. Hopefully, this script will prove to be useful for the educator desiring to place multiple choice questions on an educational Web site for feedback purposes. The two question links below provide working examples of the script in action.

Question 1

Question 2

Question 3

Question 1 is a three-part question and question 2 is a six-part question. Question 3 is of particular note as it is a four part graphical question. The question script reads the question data in from a specified file and generates an html file to present the question to the user. After the user selects an answer, the same script will read the question data file again and generate an answer html file with appropriate responses. The script is totally generic, as I hoped the question contents will show. They can be used for any topics you care to query about.

Use of the script

The script is relatively easy to use. The questions are generated by making an HREF call to the question script passing the name of the question data file you want the script to use. Here is an example call:

A HREF="server_root/question_dir/multi_question.cgi?filename=data/question1">My Question

The call for the question is located on any web page that you currently have and want to link a question from. In this example the question script is maintained in a question directory and the data files in another location . This way, subdirectories for each question can exist underneth the main data directory making question calls simple. The path to the question data file is appended with a "?" right after the script name. Simply place ?filename="your question file" at the end of the cgi call. Of course, then you place some text to indentify the HREF call. You can also check the source for this document to view the question calls. You must have a version of installed for the scripts to work. This is a very nice script that will handle retrieving and splitting apart the input stream from the user so that the cgi script can work with the information.

Script calling flow diagram

Data files

The question script must be feed a steady diet of the same bland data format or it won't work properly. Here is a sample data file.

  1. # Next two lines are the question title and subject
  2. SEQ Question
  3. Analytical Techniques
  4. # Next line is the question to be asked
  5. Which of the following techniques isn't a form of chromatography?
  6. # The next X lines are for the X number of answers for the question
  7. LC
  8. GC
  9. SEC
  10. HPLC
  11. TLC
  12. ROTC
  13. # The next two lines contain the numeric value of the correct answer and the explaination
  14. 6
  15. Obviously, ROTC isn't a form of chromatography.
  16. # The next four lines are solts for features not implimented
  17. NA
  18. NA
  19. NA
  20. NA

    The data file includes comments denoted with a # and they must be present in the data file for the scripts to work. Each line is terminated with a hard return. The questions can have any number of answers but the answers must start on line 7 of the data file. I suggest just using a blank question form and filling it in when necessary. The question data file must end with the .qdf extension for identification. Here is an example file:

    Sample data file

    Sample data file with graphics

    The Script

    Here are links to the script itself. You may use this script for your own purposes, all we ask is that you send email to us and let us know.

    View the script

    This probably isn't the best example Perl code in the known world, but, twas my first attempt at Perl programming and I am only a humble chemist.

    The scrpit operation is fairly straightforward. The question is presented in multiple choice format. The user is to select an answer and hit the submit answer button. If the user doesn't select an answer, this state is trapped out and the user is given a link back to the question. Both correct and incorrect responses are given an explination of the question answer. The responses can be changed by setting the proper variables at the beginning of the script. Check the script comments. It would be a simple matter to add code to gather student id's and log the responses to a file. We currently do this at our site but thought that a more general serving script would be useful for most people.

    Question script flow diagram

    Let us know you're using the scripts.


    This hypermedia page is maintained and copyrighted by Ron Earp.