|
Revision 2095, 1.4 kB
(checked in by joshr, 7 months ago)
|
show the program name in our TEST_VERBOSE output.
|
| Line | |
|---|
| 1 |
package GetDictionaryWords; |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use warnings; |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
sub get_dictionary_words { |
|---|
| 12 |
my $dict = shift; |
|---|
| 13 |
my ($case_sensitive) = (shift || 0); |
|---|
| 14 |
my ($max_words) = (shift || 0); |
|---|
| 15 |
my @words; |
|---|
| 16 |
my %word_count; |
|---|
| 17 |
|
|---|
| 18 |
print STDERR "$0: Loading dictionary...\n" if $ENV{TEST_VERBOSE}; |
|---|
| 19 |
open (my $fh, "<", $dict)|| die "$0: Couldn't open $dict: $!"; |
|---|
| 20 |
|
|---|
| 21 |
while( defined( my $word = <$fh> ) && ($max_words == 0 || scalar(@words) < $max_words)) { |
|---|
| 22 |
$word =~ s/[-',.<>]//g; # strip stuff |
|---|
| 23 |
chomp $word; # strip newline |
|---|
| 24 |
$word =~ s/^\s+//; |
|---|
| 25 |
$word =~ s/\s+$//; |
|---|
| 26 |
if($word =~ /^$/) { |
|---|
| 27 |
warn "Skipping empty non-word '$word'\n"; |
|---|
| 28 |
next; |
|---|
| 29 |
} |
|---|
| 30 |
push(@words, $word); |
|---|
| 31 |
my ($counted_word) = ($case_sensitive ? $word : lc($word)); |
|---|
| 32 |
$word_count{$counted_word}++; |
|---|
| 33 |
} |
|---|
| 34 |
close $fh || die "$0: Couldn't close $dict: $!"; |
|---|
| 35 |
return (\@words, \%word_count); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
1; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|