Bryan Sant wrote:
Here are the current results for the "count the dictionary words in a
file" programs submitted thus far.
Here's an non optimized Perl version. I just wanted to do a quick
version that squashed the main work into a single line, without using
deep magic. Like most posted, it assumes the text will be 'normal' (eg,
not one word per line like the dictionary file), although, I did split
out on more than whitespace, which I saw some do, as that will include
punctuation with a word ( hello!, what?, etc. ), it would be faster
without that. It also does no form of safety checking besides the open
calls, and attempts to load everything into memory.
Now, for the next trick, maybe we'll do one all in Regex :)
Once again, this is not normal code, in NO way can it be related as a
preferred, or even condoned style! it is supposed to be all squashed up
and chained together :) And yes, it could be squashed a bit more if I
wanted.
--
Jayce^
#!/usr/bin/perl
use strict;
use File::Slurp;
my @dict = read_file( '/usr/share/dict/words' ) || die q{ can't open dictionary
file } ;;
my @wordlist = map { lc($_) } split(/\W+/, read_file( $ARGV[0] ) );
my %seen = ();
my @unique = map { grep ( /$_/, @dict) ? $_: undef } grep { ! $seen{ $_ } ++ }
@wordlist ;
foreach ( @unique ) {
print $_ , ' : ', $seen{ $_ }, "\n";
}
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/