#!/usr/bin/perl use strict; $|++; use Lingua::Ispell qw(:all); use CGI qw(standard); # override the default path - Your Mileage May Vary $Lingua::Ispell::path = '/usr/bin/ispell'; my $cgi = new CGI; print $cgi->header; if (my $query = $cgi->param('query')) { &print_form; &print_corrections($query); } else { &print_form; } #thanks to Randall for this slick dereferencing trick sub print_form { print <<_FORM_;

Spell Checker


@{[$cgi->startform('POST',$cgi->script_name)]}

Enter Text To Spell Check: @{[$cgi->textfield('query')]} @{[$cgi->submit('Go')]} @{[$cgi->endform]}


_FORM_ } sub print_corrections($) { my $query = shift; print "Results for '$query' :

"; for my $result (spellcheck($query)) { my $term = "$result->{'term'}"; if ($result->{'type'} eq 'miss') { print "'$term' was not found in the dictionary,
\n"; print "Near misses: "; print join(',', @{$result->{'misses'}}), "

\n"; } elsif ($result->{'type'} eq 'none') { print "No match for term '$term'.

\n"; } } }