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) {
}
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;
}
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}",
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);
# 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;
}
}
else {
- for my $db (qw(length position)) {
+ for my $db (@dbs) {
$database->{$db} = {};
tie %{$database->{$db}}, MLDBM => "$dir/db_${db}",
O_RDONLY, 0666