Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Text-SpellChecker error

by sarvan (Sexton)
on Jun 23, 2011 at 17:38 UTC ( #911118=perlquestion: print w/replies, xml ) Need Help??

sarvan has asked for the wisdom of the Perl Monks concerning the following question:

hi there,

I installed cpan module Text::Spellchecker and all its dependencies properly. Installation was successful.

But, when i tried to run the synopsis code they hv given in cpan it given me the following error

<err> Can't call method "check" on an undefined value at /usr/local/share/perl/5.10.1/Text/ line 263.
use strict; use warnings; use Text::SpellChecker; ($Text::SpellChecker::pre_hl_word, $Text::SpellChecker::post_hl_word) = (qw([ ])); my $checker = Text::SpellChecker->new(text => "Foor score and seve +n yeers ago"); while (my $word = $checker->next_word) { print $checker->highlighted_text, "\n", "$word : ", (join "\t", @{$checker->suggestions}), "\nChoose a new word : "; chomp (my $new_word = <STDIN>); $checker->replace(new_word => $new_word) if $new_word; } print "New text : ".$checker->text."\n";
please give me suggestion why the error is coming.. Thanks..

Replies are listed 'Best First'.
Re: Text-SpellChecker error
by toolic (Bishop) on Jun 23, 2011 at 17:58 UTC
    I installed Text::SpellChecker. Your code runs for me without errors on perl version 5.8.9, but I get your error on version 5.12.2.

    I copied the relevant code from and placed a comment on line 263:

    sub next_word { my $self = shift; pos $self->{text} = $self->{position}; my $word; my $sp = $self->_hunspell || $self->_aspell; while ($self->{text} =~ m/([a-zA-Z]+(?:'[a-zA-Z]+)?)/g) { $word = $1; next if $self->{ignore_list}{$word}; last if !$sp->check($word); # 263

    There were many regex changes introduced in perl 5.10. I would start looking there. I have no time to investigate further right now. I would make a local copy of this .pm file and start adding print statements to debug it further.

    This should be submitted as a bug report. (Update: looks like the author is aware of this issue). Here is a reduced code example which still reproduces the error:

    use warnings; use strict; use Text::SpellChecker; my $checker = Text::SpellChecker->new( text => "Foor" ); my $word = $checker->next_word;
Re: Text-SpellChecker error
by davido (Cardinal) on Jun 23, 2011 at 19:04 UTC

    I believe it's a dependency issue related to the GNU Aspell library. You need the library installed along with its development headers. On Ubuntu Linux I installed the following packages via sudo apt-get:

    • libtext-aspell-perl
    • libpspell-dev

    libpspell-dev brought in another dependency at the same time: libaspell-dev

    Once I got those packages installed your snippet no longer produced the error you reported, for Perl 5.14.0.


Re: Text-SpellChecker error
by bduggan (Pilgrim) on Jun 23, 2011 at 19:44 UTC
    Text::Spellchecker can use either Text::Aspell or Text::Hunspell as a backend. Which do you have installed?

    (On a side note, can anyone tell me what the best practices are for representing alternative dependencies in a cpan module?)


      Text::SpellChecker is with a capital C (pretty important if one uses copy/paste to install them with cpan to see what is wrong).

      toolic already found that there is some difference in the behavior under different perl versions. Note that Text::Hunspell's install under perl-5.14 is in need of an update:

      Use of qw(...) as parentheses is deprecated at inc/Devel/ l +ine 191.

      Enjoy, Have FUN! H.Merijn
        Thanks. I reproduced the error but it only occurred because Text::Hunspell was missing in my install of perl 5.14. I released a new version of Text::SpellChecker yesterday with some better tests, and more diagnostics on failure (since there are a number of ways that the failure in the OP can occur : missing dictionaries, custom installation paths, ...)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://911118]
Approved by toolic
Front-paged by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-09-26 19:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found