#!/usr/bin/perl #*** This example shows the use of radio buttons, and drop #*** down list boxes. #*** This is an example of a simple "self scoring" questionare #*** Three questions are asked. Each question has a VALUE= of #*** between 1-3. The points are added together giving a #*** score of bewtween 3-9. The text message matching this #*** score is looked up on a table of text messages, and is #*** printed back to the users browser. #*** This example shows the use of radio buttons, and drop #*** down list boxes. #****************************************************************** #******************** Tables ************************************* #****************************************************************** @catagorey_table = ('Net User', 'Net Enthusiast', 'Net Hobbyist', 'Net Head', 'Real Net Head', 'Total Net Head', 'Absolute Total Net Head'); #****************************************************************** #******************** Subroutines ******************************** #****************************************************************** #******************************************************* #****** Get "state" info passed up from Browser ******** #******************************************************* sub GET_FORM_DATA { #** When the user clicks on the Submit button labled #** "Calculate Score" this CGI program is called, and the form #** data is passed in STDIN. read(STDIN, $save_string, $ENV{CONTENT_LENGTH}); # Yes- Use it @prompts = split(/&/,$save_string); foreach (@prompts) { ($tmp1, $tmp2) = split(/=/,$_); $tmp2 =~ s/\x2b/\x20/g; $tmp2 =~ s/%2C/\x2c/g; $tmp2 =~ s/%28/\x28/g; $tmp2 =~ s/%29/\x29/g; $fields{$tmp1}=$tmp2; } $question1 = $fields{'question1'}; $question2 = $fields{'question2'}; $question3 = $fields{'question3'}; } #******************************************************* #************ Send back Report Page **************** #******************************************************* sub SHOW_SCORE { print("Content-Type: text/html\n\n"); print("Heres Your Score\n"); print("\n"); print "

Heres your score:

"; $score = $question1 + $question2 + $question3; print "Your score is- ", $score; print " This makes you a "; print $catagorey_table[$score-3], ""; print "
"; print "See the Perl Source Code"; print " (selfscre.cgi) for this page\n"; print "
"; print "Back to Self Scoring Questionare"; print "
"; print "Back to Examples Page"; print"\n"; print(""); print(""); } #******************************************************* #******************** Main Rtn ************************ #******************************************************* &GET_FORM_DATA; &SHOW_SCORE;