This is a little crude, but given a less eclectic words file than the one I have, it might do better. In any case, it shouldn't be too hard to come up with a heuristic for making the decision, possibly based on the number or proportion of 1 and 2 character words or the average word length for example.
This code #! perl -sw
use vars qw($debug);
use strict;
local $\=$/;
sub IsWord {
no warnings;
return if not @_ or length == 1;
my ($word, $first, $c2n3) = $_[0] =~ /^((.)(..?)?.*)$/;
$c2n3 = substr( $c2n3 . '__', 0, 2);
local $_ = do{ local (@ARGV,$/) = "c:/test/words/$first/$c2n3"; <>
+ };
return /^$word$/im;
}
while(<DATA>) {
chomp(my $phrase = $_);
my $c= - length $phrase;
my @words;
while (length $phrase) {
my $bit = substr($phrase, $c);
if (IsWord($bit)) {
unshift @words, $bit;
$phrase = substr($phrase, 0, $c);
$c = - length $phrase;
}
else {
++$c;
last if 0 == (length($phrase)- $c);
}
}
print "${_}may consist of the words\n@words\n";
}
__END__
hudjheuhfnnvgxvbchnfhfujryyfgbch
whererangesarealltherage
thequickbrownfoxjumpsoverthelazydog
hsdkjfhuewfklJLKSDossfdlkjaslduasl
PeterPiperPickedAPeckOfPickledPepper
lazinessimpatiencehubris
Gives
C:\test>209141
hudjheuhfnnvgxvbchnfhfujryyfgbch
may consist of the words
hu dj he uhf n nv g xv bch n f h fu j ry y f g bch
whererangesarealltherage
may consist of the words
where range sare all the rage
thequickbrownfoxjumpsoverthelazydog
may consist of the words
the quick brown fox jumps over the lazy dog
hsdkjfhuewfklJLKSDossfdlkjaslduasl
may consist of the words
hs dk j f hu ew f kl J L KS Doss f d l k jas l du as l
PeterPiperPickedAPeckOfPickledPepper
may consist of the words
Peter Piper Pick edA Peck Of Pickled Pepper
lazinessimpatiencehubris
may consist of the words
laziness impatience hubris
C:\test>
Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|