You are probably thinking, "It must be another slow day at the Chum-Bucket." and you would be right. Here is a CGI version of a jumble solver Perl script I wrote a while back with POD even!
#!/usr/bin/perl -wT
=head1 Name
jumbler.pl - Jumble Solver Perl CGI
=head1 Description
A simple Perl CGI that solves word jumbles.
=head1 Arguments and Options
jumbler.pl expects only one argument and that is the jumble
it is to solve.
=head1 Prerequisites
jumbler.pl uses the CGI CPAN module.
jumbler.pl also needs to call a shell script called spelled
to do spell checking (see below). The script below assumes
your system has aspell installed.
=item Speller shell script
#!/bin/sh
# This file should be named spelled and exist in the same
# directory as jumbler.pl exist.
ASPELL=/usr/bin/aspell
GREP=/usr/bin/grep
EGREP=/usr/bin/egrep
for i in $*
do
correct=`echo $i | $ASPELL -a | $GREP -v '^@' | $GREP -v '
+^&' | $EGREP -v '^$'`
if [ ! -z "$correct" ]
then
echo "$i"
fi
done
=head1 Example use
=item Command-line
Plankton@Chum-Bucket ~/cgi-bin
$ ./jumbler.pl WORD=enmog
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><tit
+le>Jumble solver</title>
</head><body><HR>enmog<HR><BR>
.oOo.oOo.o[gnome]<BR>
Oo</body></html>
=item CGI
<HTML>
<HEAD><TITLE>Jumbler</TITLE>
</HEAD>
<BODY>
<FORM ACTION=../cgi-bin/jumbler.pl METHOD=POST>
Enter a jumble:<INPUT TYPE=TEXT NAME=WORD>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
=head1 Miscellaneous information
jumbler.pl is an example of Perl CGI that use the CPAN module CGI.
jumbler.pl uses $| and "print" to prevent the browser from timing
+out.
jumbler.pl is a example of the use of a recursive permution algori
+thm.
=cut
$ENV{'PATH'} = "";
use strict;
use CGI;
use CGI::Carp qw /fatalsToBrowser/;
my $out = new CGI;
my $word = lc($out->param ( 'WORD' ));
$word =~ s/ //g;
# don't use this anymore! $|++;
# do this ...
$|=1;
# ... instead
# see http://www.perlmonks.com/index.pl?node_id=344772
my $loopCount = 0;
my $charCount = 0;
($word) = $word =~ /^(\w+)$/ or die "Bad User! passing word=[$word]";
my @chars = split //, $word;
my $speller ="spelled";
sub spelled {
my $word = shift;
my $out=`$speller $word`;
chomp($out);
if ( ($loopCount++ % 10) == 0 ) {
print "." if ($charCount % 4) == 0;
print "o" if ($charCount % 4) == 1;
print "O" if ($charCount % 4) == 2;
print "o" if ($charCount % 4) == 3;
$charCount++;
print "<BR>\n" if ($charCount % 29 ) == 0;
}
if ( length($out) > 0 ) {
print "[$out]<BR>\n";
}
}
sub swap {
my $i = shift;
my $j = shift;
my $A = shift; # ref to array
my $tmp = @{$A}[$i];
@{$A}[$i] = @{$A}[$j];
@{$A}[$j] = $tmp;
}
sub permute {
my $i = shift;
my $n = shift;
my $T = shift; #ref to array
if ( $i == $n ) {
my $word = join( "", @{$T} );
spelled( $word );
} else {
for my $j ( $i..$n) {
swap( $i-1, $j-1, $T );
permute( $i+1, $n, $T );
swap( $i-1, $j-1, $T );
}
}
}
print $out->header( 'text/html' );
print $out->start_html( 'Jumble solver' );
print "<HR>$word<HR><BR>\n";
permute (1,$#chars+1,\@chars);
print $out->end_html();
Plankton: 1% Evil, 99% Hot Gas. |