axtens wrote:
On Feb 1, 10:00 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
axtenswrote:
G'day everyone
Thanks for that. I did, however, give up on using TwoWay and used an
idea a colleague had given me, as below:
sub Misspellings_Setup {
@wordsList = split /\n/, <<'__WORDLIST__'
abandonned abandoned
aberation aberration
abilities abilties
.
.
.
__WORDLIST__
;
Why not just create @wordsList as an AoA so you don't have to do all
that splitting:
my @wordsList = (
[ 'abandonned', 'abandoned' ],
[ 'aberation', 'aberration' ],
[ 'abilities', 'abilties' ],
...
);
foreach (@wordsList) {
($left, $right) = split /\t/, $_;
@leftList = split /,\s* /, $left;
@rightList = split /,\s*/, $right;
I didn't see any commas in your data so what is this supposed to be doing?
foreach $l (@leftList) {
foreach $r (@rightList) {
if ( exists $misDict{"!-$l"} ) { $misDict{"!-$l"} .= $r . "^"; }
else { $misDict{"!-$l"} = $r . "^"; }
if ( exists $misDict{"?-$r"} ) { $misDict{"?-$r"} .= $l . "^"; }
else { $misDict{"?-$r"} = $l . "^"; }
You don't have to test for the key existence as perl will autovivify the
values.
}
}
}
}
misDict is an "our" declared elswhere. Getting something out of the
hash is as below.
sub Misspellings_Suggest {
#receives string
#returns string
my $res;
my $string = shift;
if ( ! %misDict ) {
Misspellings_Setup();
}
if ( exists( $misDict{"!-$string"} ) ) {
$res = $misDict{"!-$string"};
} else {
$res = $string;
}
$res =~ s/\^/FS/ge;
The /e option evaluates the "FS" string as perl code but it is not perl
code so why use the /e option?
return $res;
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/