#!/usr/local/bin/perl use CGI qw/:standard unescape/; # This code segment is designed to accept parameters via HTTP to CGI # and spell check each word. The resulting output is displayed with # non-match words highlighted. my $open_html_indicator = ''; my $close_html_indicator = ''; my $i; my %hash; my %misspelled_words; my $varname; my $mydata; my %dict; # Parse the parameters from the calling HTTP line my @values = split(/&/,$ENV{'QUERY_STRING'}); foreach $i (@values) { ($varname, $mydata) = split(/=/,$i); $hash{$varname} = unescape($mydata); #unescape clears out http %20 etc. } # Response header to send back to the requesting web page print header; print << 'EOL'; Spell Check API Example EOL # Load the dictionary word list into a hash open DICT,"){ chomp; $dict{lc($_)}=1; } close DICT; print "

The following $open_html_indicator highlighted $close_html_indicator words" . " are not found in the English dictionary


"; print ""; while ( ($varname, $mydata) = each %hash ) { my @words=split /[^a-zA-Z0-9']+/,$mydata; foreach (@words){ if(!defined $dict{lc($_)}){ if(!defined $misspelled_word{$_}){ # If the data is already caught , then move on $misspelled_word{$_} = 1; $mydata =~ s/$_/$open_html_indicator $_ $close_html_indicator/g; } } } print ""; } print "

$varname: $mydata
"; print "

Spell Check API Example "; print ""; print "";