From fc301dbcc29fde40377a37c233e379bd932a8449 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 17 Jan 2009 01:15:03 +0000 Subject: [PATCH] ( update anamang to actually load the databases --- anamang | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/anamang b/anamang index 78f0ea3..d63874f 100755 --- a/anamang +++ b/anamang @@ -234,6 +234,7 @@ sub find_allowable_words { sub update_and_load_database { my ($dir,$wordlist) = @_; # check to see if the wordlist is newer than our database + my @dbs = qw(length position substitution rotation anagram); my $update_required = 0; my $wordlist_time = 1; if (! -r $wordlist) { @@ -241,7 +242,7 @@ sub update_and_load_database { } my $wordlist_stat = stat($wordlist); $wordlist_time = max($wordlist_time,$wordlist_stat->mtime); - for my $db (qw(length position)) { + for my $db (@dbs) { if (! -e "$dir/db_${db}") { $update_required = 1; } @@ -255,7 +256,7 @@ sub update_and_load_database { if (not -d "$dir") { mkdir($dir) or die "Unable to create directory $dir: $!"; } - for my $db (qw(length position substitution rotation anagram)) { + for my $db (@dbs) { $database->{$db} = {}; $disk_db->{$db} = {}; tie %{$disk_db->{$db}}, MLDBM => "$dir/db_${db}", @@ -274,7 +275,7 @@ sub update_and_load_database { next if exists $seen_words{$word}; $seen_words{$word} = 1; if ((keys %seen_words) % 100 == 0) { - print STDERR "Handled ".(keys %seen_words) . "words, on $word\n"; + print STDERR "Handled ".(keys %seen_words) . " words, on $word\n"; } my @l = split //, $word; my $l = length($word); @@ -317,6 +318,9 @@ sub update_and_load_database { # in it, hello becomes axeeh, giddy acxxs my $fl = $l[0]; my $index = $l_o{$fl}; + if (not defined $index or grep {not exists $l_o{$_}} @l) { + print STDERR "Problem with some letters in '$word'\n"; + } $mapped_word = join('',map {$l_o[($l_o{$_} - $index + 26) % 26]} @l); $temp = $database->{rotation}{$mapped_word}; $temp = [] if not defined $temp; @@ -338,7 +342,7 @@ sub update_and_load_database { } } else { - for my $db (qw(length position)) { + for my $db (@dbs) { $database->{$db} = {}; tie %{$database->{$db}}, MLDBM => "$dir/db_${db}", O_RDONLY, 0666 -- 2.39.5