[Instructions] [Search] [Current] [Readings] [Syllabus] [Links] [Handouts] [Outlines] [Assignments]
http://www.math.grin.edu/~rebelsky/Courses/Tutorial/99F/Handouts/madalice1.html.
http://www.math.grin.edu/~rebelsky/Courses/Tutorial/99F/Handouts/madalice2.html.
<HTML> <HEAD> <TITLE>Prepare for a Story</TITLE> </HEAD> <BODY> <H1>Write your own adventure ...</H1> <FORM METHOD="GET" ACTION="madalice.cgi"> <P> Enter your name: <INPUT TYPE="text" NAME="name"> </P> <P> Enter your gender: <SELECT NAME="gender"> <OPTION VALUE="male">Male <OPTION VALUE="female">Female <OPTION VALUE="other" SELECTED>Indeterminate </SELECT> </P> <P> Enter some singular nouns: <INPUT TYPE="text" NAME="noun1" VALUE="eggplant"> <INPUT TYPE="text" NAME="noun2" VALUE="Web page"> <INPUT TYPE="text" NAME="noun3" VALUE="zebra"> </P> <P> Enter an exclamation, like ``Hey!'' or ``Cool!'' or ``Wicked neat!'' <INPUT TYPE="text" NAME="exclamation" VALUE="Sweet!"> </P> <INPUT TYPE="HIDDEN" NAME="adjective1" VALUE="strange"> <INPUT TYPE="HIDDEN" NAME="adjective2" VALUE="fascinating"> <INPUT TYPE="HIDDEN" NAME="adjective3" VALUE="beautiful"> <INPUT TYPE="HIDDEN" NAME="adjective4" VALUE="cloudy"> <INPUT TYPE="HIDDEN" NAME="beverage" VALUE="orange juice"> <INPUT TYPE="SUBMIT" VALUE="Tell me a story"> </FORM> </BODY> </HTML>
What do you think each part of this does?
#!/usr/local/bin/perl
# A simple, Mad-libs (tm) type CGI script that tells a story based
# on parameters given in a form page. The following are the
# parameters used in the story:
#
# Name, Gender,
# Adjective1, Adjective2, Adjective3
# Noun1,Noun2,Noun3
# Exclamation
use CGI;
# Get the query from the Web page
$query = CGI::new();
# Extract the important parts.
$name = $query->param("name");
$gender = $query->param("gender");
$adj1 = $query->param("adjective1");
$adj2 = $query->param("adjective2");
$adj3 = $query->param("adjective3");
$adj4 = $query->param("adjective4");
$noun1 = $query->param("noun1");
$noun2 = $query->param("noun2");
$noun3 = $query->param("noun3");
$exclamation = $query->param("exclamation");
$beverage = $query->param("beverage");
# Find an appropriate pronoun
if ($gender eq "male") {
$pronoun = "he";
$Pronoun = "He";
$possessive = "his";
}
elsif ($gender eq "female") {
$pronoun = "she";
$Pronoun = "She";
$possessive = "her";
}
else {
$pronoun = "it";
$Pronoun = "It";
$possessive = "its";
}
# The ending depends on the exclamation
if ($exclamation eq "Wicked neat!") {
$ending = "``What a satisfying drink,'' $name thought as " .
"$pronoun put the bottle down.";
}
else {
$ending = "As $name collapsed to the floor, $pronoun thought, " .
"``I really do need to learn to read the label first!''";
}
print $query->header();
print <<"END";
<HTML>
<HEAD>
<TITLE>A Story for $name</TITLE>
</HEAD>
<BODY>
<H1>${name}'s adventures at the bottom of the slide</H1>
<P>
$name was feeling very dizzy when $pronoun reached the bottom of
the slide. The room was spinning and $name thought $pronoun saw
$adj1 ${noun1}s bouncing around the room. $name felt very, very
$adj2.
</P>
<P>
Once $pronoun had recovered, $pronoun began to look around the room.
$Pronoun quickly noticed a $adj3 $adj4 glass bottle that seemed to
be filled with $beverage. The bottle was near a $noun.
As $pronoun was quite thirsty and also
enamored of $beverage, $name thought ``$exclamation'' and
decided to drink the bottle. As $possessive
lips touched the bottle, $pronoun saw the words ``Are you sure you
want to drink me?''
</P>
<P>
$ending
</P>
</BODY>
</HTML>
END
[Instructions] [Search] [Current] [Readings] [Syllabus] [Links] [Handouts] [Outlines] [Assignments]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/Tutorial/99F/Handouts/madlab.html
Source text last modified Tue Oct 26 08:23:00 1999.
This page generated on Tue Jan 25 09:09:33 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu