in reply to Help finding mistakes in spellings using Perl
Hi shamat,
Dear Monks, I am a newbie in Pearl,..
Let me start by saying, if you are still new to Perl is not late to start good habit like use warnings and strict in your script.
Secondly, make your script readable use perltidy
The first entry in the list always refers to the correct spelling. I would like to find the mistakes in the entries 1-3, checking against the reference word. I would like to obtain an output like this:
One way to go is to compare each of the string with the first entry, letter by letter.
I will give a head up below.
Produces..use warnings; use strict; my @words = qw(believe beleive beeliv pelief); spelling_check( $words[0], $_ ) for @words[ 1 .. $#words ]; sub spelling_check { no warnings 'uninitialized'; my @wrds; push @wrds, [ split //, $_ ] for @_; my ( $right, $wrong ) = q{} x 2; for ( 0 .. $#{ $wrds[0] } ) { if ( $wrds[0]->[$_] ne $wrds[1]->[$_] ) { $right .= defined( $wrds[1]->[$_] ) ? $wrds[1]->[$_] : qw' +-'; $wrong .= defined( $wrds[0]->[$_] ) ? $wrds[0]->[$_] : qw' +-'; } } print join( ' ~ ' => ( $right, $wrong ) ), $/; }
NOTE: Please, note that if either of the strings comparing per time is longer, you have "uninitialized value" thus I used no warnings 'uninitialized'ei ~ ie eli- ~ liee pf- ~ bve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help finding mistakes in spellings using Perl
by shamat (Acolyte) on Oct 10, 2013 at 15:33 UTC |