Current results of "dictionary word count" programs...

Alan Young alansyoungiii at gmail.com
Wed Mar 15 11:38:43 MST 2006


Here's my perl contribution:

#!/usr/bin/perl -w

use strict;

use File::Slurp;

my ( %dictionary, %not_in_dictionary );

{ my @dictionary = do {
    open my $D, "</usr/share/dict/words"
      or die "Couldn't open words file: $!\n";
    <$D>;
  };

  shift @dictionary;
  chomp @dictionary;

  @dictionary{ @dictionary } = ( 0 ) x @dictionary;
};

my $text = do {
 open my $T, '<./kjv10.txt'
   or die "Couldn't open kjv10.txt: $!\n";
 local $/;
 <$T>;
};

( exists $dictionary{ $1 }
  ? $dictionary{ $1 }++
  : $not_in_dictionary{ $1 }++
) while $text =~ m/([\w'-]+)/g ;

print "\n\nThese words appeared N times and were in the dictionary:\n\n";
print "Dictionary word -> times appeared\n";
print "---------------------------------\n\n";

print join "\n", map { "$_ -> $dictionary{ $_ }" } sort keys %dictionary;

print "\n\nThese words appeared and were not in the dictionary:\n\n";
print "Non-Dictionary word -> times appeared\n";
print "-------------------------------------\n\n";

print join "\n", map { "$_ -> $not_in_dictionary{ $_ }" } sort keys
%not_in_dictionary;


--
Alan



More information about the PLUG mailing list