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

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


Here's the whole thing again after I took another swing through it.

#!/usr/bin/perl -w

use strict;

use File::Slurp;

my ( %dictionary, %not_in_dictionary );

sub getfile { local *ARGV ; @ARGV = shift ; wantarray ? map /(.*)/, <>
: do { local $/ ; <> } }

%dictionary = map { ( $_, 0 ) } grep { ! /^\s*$/ } getfile(
'/usr/share/dict/words' );

my $text = getfile( './kjv10.txt' );

( 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