2.2 The Engine Document

Consider the following Perl program, which we are imagining is hosted as the web-based application program "something.cgi" at the internet domain "example.com":

#!/usr/bin/perl

use CGI qw(:standard);
use strict;

my $color = param("sys_argument");

my @red_things = ("Apples", "Lips", "Hearts");
my @green_things = ("Frogs", "Shamrocks", "Olives");
my @blue_things = ("Jeans", "Blueberries", "Blue jays");

my $thing;
if ($color eq "red") {
  $thing = $red_things[int(rand($#red_things+1))];
} elsif ($color eq "green") {
  $thing = $green_things[int(rand($#green_things+1))];
} elsif ($color eq "blue") {
  $thing = $blue_things[int(rand($#blue_things+1))];
}

my $content;
if ($thing) {
  $content = "$thing are $color";
} else {
  $content = "Try red, green, or blue";
}

print header;
print <<EOF
<message>
  <content>$content</content>
</message>
EOF
;