I have a script on my site that is for the old "Mad Libs"
type game where you put in a word and it puts it in the
story for you.
That may be able to be adapted directly.
The script is by Darryl Burgdorf
http://awsd.com/scripts/ Here's the main part of it.
_____________________________
$InputFile = "/mysite.com/cgi-bin/funnyads/funnyads.htm";
$TextFile = "/mysite.com/cgi-bin/funnyads/text";
$CGIURL = "
http://mysite.com/...funnyads/funnyads.pl";
print "Content-type: text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($FORM{$name}) {
$FORM{$name} = "$FORM{$name}, $value";
}
else {
$FORM{$name} = $value;
push (@variables,$name);
}
}
if ($FORM{'TextFile'}) { &SendFile; }
if (-d $TextFile) {
opendir(FILES,$TextFile);
@tempfiles = readdir(FILES);
closedir(FILES);
foreach $file (@tempfiles) {
if (-T "$TextFile/$file") {
push (@files, $file);
}
}
srand();
$files = @files;
$file = @files[int(rand($files))];
$TextFile = $TextFile."/".$file;
}
open (FILE,"$TextFile");
@LINES = <FILE>;
close (FILE);
$text = join(' ',@LINES);
$text =~ s/\n/ /g;
$text =~ s/</\n</g;
$text =~ s/>/>\n/g;
@text = split('\n',$text);
undef (@variables);
foreach $line (@text) {
if ($line =~ s/<!--(.*)-->/$1/) {
push (@variables,$line);
}
}
@sortedvariables = sort (@variables);
open (FILE,"$InputFile");
@LINES = <FILE>;
close (FILE);
foreach $line (@LINES) {
if ($line =~ /<!--InputWords-->/i) {
print "<FORM METHOD=POST ACTION=\"$CGIURL\">\n";
print "<INPUT TYPE=HIDDEN NAME=TextFile ";
print "VALUE=\"$TextFile\">\n";
print "<P><CENTER><TABLE>\n";
foreach $variable (@sortedvariables) {
next if ($variable eq $lastvariable);
print "<TR><TD ALIGN=RIGHT><P>$variable: </TD>";
print "<TD><INPUT TYPE=TEXT NAME=\"$variable\" SIZE=25>";
print "</TD></TR>\n";
$lastvariable = $variable;
}
print "</TABLE></P>\n";
print "<P><INPUT TYPE=SUBMIT VALUE=\"Create Funny Ads\">\n";
print "</CENTER></P></FORM>\n";
}
else {
print $line;
}
}
exit;
sub SendFile {
open (FILE,"$FORM{'TextFile'}");
@LINES = <FILE>;
close (FILE);
$text = join(' ',@LINES);
$text =~ s/\n/ /g;
foreach $variable (@variables) {
if ($FORM{$variable} eq "") {
print "incomplete!\n";
exit;
}
$text =~ s/<!--$variable-->/<STRONG>$FORM{$variable}<\/STRONG>/g;
}
$text =~ s/A\/an <STRONG>(a|e|i|o|u)/An <STRONG>$1/g;
$text =~ s/a\/an <STRONG>(a|e|i|o|u)/an <STRONG>$1/g;
$text =~ s/A\/an/A/g;
$text =~ s/a\/an/a/g;
print $text;
exit;
}
_____________________________
In the HTML page you simply insert:
<!--InputWords-->
_____________________________
Then in the cgi-bin/funnyads/text directory you put as many
.txt files as you want that each look something like:
Nike--Just <!--Verb--> it!
or
General Electric--We Bring <!--Adjective--> Things to Life
_____________________________
One problem with the script is that it randomly selects the
.txt file from the cgi-bin/funnyads/text directory but it
does not check to see if that .txt file has been used before
so you might get the same one whenever you refresh the
page.
_____________________________
You can take a look at the script in action on my site:
http://churchfun.com/...nt_announcements.htm _____________________________
Really, if there was just a way to make sure that the files
don't repeat themselves this would be perfect for the slogan
script.
Now, I don't pretend to know much PERL. I can cut and paste
and set permissions and MAYBE change a variable or two.
I guess I know just enough to be picky about how the script
works.
If there is any way to modify the script or if you can think
of a better way to do this it would be great.
Thank you for looking at this.