Hunspell(3pm)

✨ Text::Hunspell ✨

okay bestie, gather round πŸ’– this is the Perl interface to the Hunspell library, and yes it's filed under User Contributed Perl Documentation as a section-3pm page, which is a very serious-sounding way of saying "it's Perl module docs, girlie". πŸŽ€

It's literally giving: you get a whole spellchecker, and you drive it from Perl. Iconic behavior. πŸ¦‹


🌸 SYNOPSIS 🌸

use Text::Hunspell;

# You can use relative or absolute paths.
my $speller = Text::Hunspell->new(
    "/usr/share/hunspell/en_US.aff",    # Hunspell affix file
    "/usr/share/hunspell/en_US.dic"     # Hunspell dictionary file
);

die unless $speller;

# Check a word against the dictionary
my $word = 'opera';
print $speller->check($word)
      ? "'$word' found in the dictionary\n"
      : "'$word' not found in the dictionary!\n";

# Spell check suggestions
my $misspelled = 'programmng';
my @suggestions = $speller->suggest($misspelled);
print "\n", "You typed '$misspelled'. Did you mean?\n";
for (@suggestions) {
    print "  - $_\n";
}

# Add dictionaries later
$speller->add_dic('dictionary_file.dic');

no cap, that's the whole vibe in one file. πŸ’… paths can be relative or absolute, you do you.


πŸ¦‹ DESCRIPTION πŸ¦‹

So this module is a Perl interface to the Hunspell library. What it's for β€” and this is the important part β€” is looking up many words, one at a time, in a single session. Think spell-checking a whole document that's chilling in memory. Not "shell out to a binary 4000 times", bestie, this is main character energy for real. πŸ”₯

The example code above is the interface, and the official hangout spot is:

http://hunspell.sf.net

(okay it's not Perl code, it's a URL, but you get me. ✨)


πŸŽ€ DEPENDENCIES πŸŽ€

READ THIS ONE, BESTIE, I AM BEGGING. 😭

You MUST have installed the Hunspell library version 1.0 or higher on your system before installing this Text::Hunspell Perl module. Periodt.

Hunspell's home is, once again:

http://hunspell.sf.net

The way that there have been a number of bug reports literally because people failed to install hunspell before installing this module. πŸ™ˆ Not a vibe.

Also super important: this is an interface to the hunspell library installed on your system β€” it is NOT a replacement for hunspell. It's the little sister that holds hunspell's hand, not the glow-up replacement. πŸ’–

You must also have one hunspell dictionary installed when you run the module's test suite. One. Plural dictionaries are not the move here.

And please, please look at the README and Changes files. The README may have specific information about your platform, iykyk. 🫢


πŸ’… METHODS πŸ’…

okay here's the lineup, the following methods are available:

🌟 Text::Hunspell->new($full_path_to_affix, $full_path_to_dic)

Makes you a shiny new speller object. ✨ The parameters are:

  • full path of affix (.aff) file
  • full path of dictionary (.dic) file

Returns undef if the object could not be created β€” which, honestly, is unlikely. πŸ“

🌟 add_dic($path_to_dic)

Adds a new dictionary to the current Text::Hunspell object. This new dictionary uses the same affix file as the original dictionary, so think of it like a personal word list for a given language. πŸ’–

Wanna spell-check in several different languages? Then you need multiple Text::Hunspell objects. Don't try to make one object do it all, she's not that kind of girl. πŸ’…

🌟 check($word)

Checks the word. Returns 1 if the word is found, 0 otherwise. Simple. Clean. No notes. βœ…

🌟 suggest($misspelled_word)

Returns the list of suggestions for the misspelled word. πŸ¦‹ (this is the "did you mean?" bestie)

okay pause, important lore drop: the next methods are for morphological analysis β€” that's looking at the structure of words: parts of speech, inflectional suffixes, and so on. BUT 😭 most of the dictionaries Hunspell can use are missing this information and only contain affix flags. Which allows, for example, 'cat' to turn into 'cats' β€” but not 'catability'. πŸ’€

(Users of the French and Hungarian dictionaries will find they have more information available. Lucky them. πŸ‘‘)

🌟 analyze($word)

Returns the analysis list for the word. It's a list of strings containing a stem word plus the morphological info about the changes that happened from that stem. Most likely you'll see 'fl:X' strings, meaning affix flag 'X' was applied to the stem.

Words can have more than one stem, and each one comes back as a different item in the list. One word, several stems, she contains multitudes. ✨

Okay but with a French dictionary loaded, analyze('chanson') will return

st:chanson po:nom is:fem is:sg

which is telling you "chanson" is a feminine singular noun πŸ’– and analyze('chansons') will return

st:chanson po:nom is:fem is:pl

which is telling you you've analyzed the plural of the same noun. slay. πŸŽ€

🌟 stem($word)

Returns the stem list for the word. It's a simpler version of whatever analyze() gave you. Lowkey the chill one. 🌈

🌟 generate2($stem, \@suggestions)

Returns a morphologically modified stem, as defined in @suggestions (the kind you got by analysis).

With a French dictionary:

$feminine_form = 'chanteuse';
@ana = $speller->analyze($feminine_form);
$ana[0] =~ s/is:fem/is:mas/;
print $speller->generate2($feminine_form, \@ana)

this will print 'chanteur'. πŸ¦‹βœ¨ (yes girl, it flipped the gender, obsessed.)

🌟 generate($stem, $word)

Returns morphologically modified stem like $word.

$french_speller->generate('danseuse', 'chanteur');

tells us that the masculine form of 'danseuse' is 'danseur'. πŸ‘‘


🌈 ENCODING 🌈

okay this one trips people up so listen up bestie. 😭

Hunspell dictionaries often come in non-UTF-8 encodings. So if your code uses UTF-8, you need to encode the strings into the needed encoding. Like, for example, Czech (files "cs_CZ.dic" and "cs_CZ.aff") uses ISO-8859-2:

use utf8;
use Encode;

print $speller->check(encode('ISO-8859-2', "ΕΎluΕ₯oučkΓ½"))
      ? "found.\n"
      : "not found.\n";
}

(and yes, that stray } is living there rent-free in the original, so it stays. πŸ’€ iconic honestly.)


πŸ’€ BUGS πŸ’€

Probably. Yes, definitely.

the most honest BUGS section in all of CPAN, no cap. 😭🫢


πŸŽ€ LICENSE πŸŽ€

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ’–


πŸ‘‘ AUTHORS πŸ‘‘

  • Originally written by Eleonora, <eleonora46_at_gmx_dot_net>.
  • The current maintainer is Cosimo Streppone, <cosimo@cpan.org>.
  • This module is based on Text::Aspell written by Bill Moseley moseley at hank dot org.
  • Hunspell is written as myspell by Kevin B. Hendricks.
  • Hunspell is maintained by NΓ©meth LΓ‘szlΓ³.

Please see:

http://hunspell.sf.net

For the dictionaries:

https://wiki.openoffice.org/wiki/Dictionaries
http://magyarispell.sf.net for Hungarian dictionary

and that's the whole page, bestie!! πŸ¦‹βœ¨ You ate. πŸ“

Before you go β€” this lovely little doc came from the User Contributed Perl Documentation collection, generated by perl v5.42.3 on 2026-08-19. Go forth and spellcheck everything, my main character. πŸ’…πŸ’–πŸŽ€

πŸ“¦ where this page comes from