#!/usr/bin/perl -w # use strict; # in order for this to work you will need the Text::Aspell package from CPAN use Text::Aspell; my $VERSION = 1.0.1; sub usage() { # spits out a useage message. Since this script is pod documented we will # just run pod2text on ourself my $script_name = $0; system("pod2text $script_name"); exit(0); } sub aspell_lookup($$) { # looks up a single word in the local aspell word list and prints out either (a message # that the word was found) or (a list of suggested spellings). my ($aspell_handle,$spelling_word) = @_; my $found = $aspell_handle->check($spelling_word); if ($found) { printf("%s is in aspell wordlist.\n",$spelling_word); print "\n"; return } my @suggestion_list = $aspell_handle->suggest($spelling_word); if (!defined($suggestion_list[0])) { print "No spelling suggestions found for $spelling_word\n"; print "\n"; return; } my $suggestion; print "spelling suggestions for $spelling_word are:\n"; foreach $suggestion (@suggestion_list) { print " $suggestion\n"; } print "\n"; } # ------------ # main routine # ------------ my $nargs = @ARGV; if ($nargs < 1) { usage(); } my @check_words; my $argument; foreach $argument (@ARGV) { push(@check_words,$argument); } # Set up Aspell my $aspell_handle = Text::Aspell->new; die unless $aspell_handle; # if your spelling is really atrocious you may want to change # "normal" to "bad-spellers" which gives many more suggestions # and does not guess that you may have made simple typos. $aspell_handle->set_option('sug-mode','normal'); my $check_word; print "\n"; foreach $check_word (@check_words) { aspell_lookup($aspell_handle,$check_word); } __END__ =head1 README spellword - Checks the spelling of one or a few words from the command line. =head1 USAGE spellword ... This is a command line callable Perl script for checking the spelling of one (or a few) words. It looks up the word or words given on the command line in the local Aspell dictionary. If the word is found the script will say so. If the word is not found the script will list spelling suggestions =head1 COPYRIGHT AND LICENSE Copyright (C) 2008-2009 by Andrew LaRoy. All Rights Reserved. This is free software distributed under the Artistic License 2.0. Full license text is available at http://www.perlfoundation.org/artistic_license_2_0 =head1 PREREQUISITES This script requires the C module. Your system will need to have a working copy of the aspell library and aspell headers installed in order to install the Text::Aspell module. =head1 HISTORY v1.0.0 (Sept. 2008) First public release. v1.0.1 (Feb. 2009) Use normal suggestion mode rather than slow. =head1 SCRIPT CATEGORIES Search =cut