Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 = '<b><font color="#FF0000">'; my $close_html_indicator = '</b></font>'; 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'; <html><head><title>Spell Check API Example</title></head> <body> <font face="Arial" size=2> EOL # Load the dictionary word list into a hash open DICT,"</usr/dict/words2"; # This just points to a word list while(<DICT>){ chomp; $dict{lc($_)}=1; } close DICT; print "<H3> The following $open_html_indicator highlighted $close_html +_indicator words" . " are not found in the English dictionary </H3> <br>"; print "<table border='1'>"; 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 "<tr><td><br><b>$varname:</b> $mydata<br></td></tr>"; } print "</table>"; print "<br><br><font size='1'> Spell Check API Example </font>"; print "</body>"; print "</html>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is this secure?
by diotalevi (Canon) on Nov 14, 2003 at 19:49 UTC | |
|
Re: Is this secure?
by jpfarmer (Pilgrim) on Nov 14, 2003 at 19:27 UTC | |
|
Re: Is this secure?
by Anonymous Monk on Nov 14, 2003 at 19:30 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |