#! perl -sw use strict; my ($oldfirst, $oldc2n3) = ( '', '' ); open WORDS, '<', $ARGV[0] or die $ARGV[0] . $1 . $/; while() { chomp; $_ = lc; my ($first, $c2n3) = /^(.)(..?)?.*/; $first = './' . $first; $c2n3 = substr($c2n3.'__',0,2) if !defined $c2n3 or length($c2n3) < 2; $c2n3 = $first . '/' . $c2n3; if ( ($first ne $oldfirst) or ($c2n3 ne $oldc2n3) ) { mkdir $first if not -e $first; open SUB, '>>', $c2n3 or die $c2n3 . $! . $/; } print SUB $_, $/; ($oldfirst, $oldc2n3) = ($first, $c2n3); print "\r$c2n3:$_ "; } #### #! perl -sw use strict; use Benchmark::Timer; sub IsWord { return if not @_ or length == 1; my ($word, $first, $c2n3) = $_[0] =~ /^((.)(..?)?.*)$/; local $_ = do{ local (@ARGV,$/) = "./$first/$c2n3"; <> }; return /^$word$/im; } my $timer = Benchmark::Timer->new(skip=>0); for (@ARGV) { $timer->start; my $IsWord = IsWord( $_ ); $timer->stop; print $_, $IsWord ? ' is ' : ' is not ', 'a word', $/; } $timer->report; print "@{[$timer->data('_default')]}", $/; __END__ #### C:\test\WORDS>../208899-2 Anonymous Baltic Confirm Delta Entity Font Gregarious Hazzard Indigo Jalopy Kilo Lascivious Matter Notorious Ovulation Prosthetic Quinine Reading Semaphore Transendental Uniform Vivisection Weather Xenophobia Yesterday Zorro Anonymous is a word Baltic is a word Confirm is a word Delta is a word Entity is a word Font is a word Gregarious is a word Hazzard is a word Indigo is a word Jalopy is a word Kilo is a word Lascivious is a word Matter is a word Notorious is a word Ovulation is a word Prosthetic is a word Quinine is a word Reading is a word Semaphore is a word Transendental is not a word Uniform is a word Vivisection is a word Weather is a word Xenophobia is a word Yesterday is a word Zorro is a word 26 trials of _default (70ms total), 2.692ms/trial 0 0 0 0 0 0.01 0 0 0.01 0 0 0 0 0 0 0.01 0.01 0 0.01 0.01 0 0 0 0 0.01 0 C:\test\WORDS>