Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Text-SpellChecker error

by sarvan (Sexton)
on Jun 23, 2011 at 17:38 UTC ( [id://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/SpellChecker.pm 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 SpellChecker.pm 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.


    Dave

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?)

    Brian

      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/CheckLib.pm 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?
Username:
Password:

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
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found