puzzle.cgi

#!/usr/local/bin/perl -w

# puzzle.cgi
# A simple crossword puzzle helper using 'grep'
# WI Bioinformatics course - Feb 2002 - Lecture 6

use CGI qw(:standard);
$query = new CGI;

if (param())
{
   # Get input from HTML form
   $in = param("in");
}
# Eliminate any leading or trailing spaces
$in =~ s/^\s*//;      # leading
$in =~ s/\s*$//;      # trailing
# Add anchors for word boundaries 
$in_word = "\^$in\$";

# Start printing the HTML output to STDOUT 
print $query->header('text/html'); 
print "<HEAD><TITLE>Crossword puzzle helper</TITLE><HEAD>
<BODY><CENTER><H3>Crossword puzzle helper</H3></CENTER>\n";

# Run the grep command on the dictionary at /usr/share/lib/dict/words
# The -i switch makes the match case-insensitive
$out = `grep -i '$in_word' /usr/share/lib/dict/words`;

# Print output; <PRE> tag is needed to get one word per line in HTML file
print "<PRE><FONT SIZE=+1 COLOR=red><B>Matches for $in</FONT>\n\n";
print "$out<PRE>\n";

# Finish output
print $query->end_html;