Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Found a word from a set of letters

by mwah (Hermit)
on Jan 29, 2008 at 19:11 UTC ( [id://664958]=note: print w/replies, xml ) Need Help??


in reply to Found a word from a set of letters

There have been already many solutions w/word list look up posted to this thread. I'll try to give a 'hands on' example (if you work on a windows box).

First, you could download a dictionary from

ftp://ftp.ox.ac.uk/pub/wordlists/american/dic-0294.tar.gz

and put it in a directory, eg. "c:\dic-0294" (extract it *there*, winrar or winzip should work)
You'll see ~30 different files, each containing words of a defined length.

Then, create a Perl script like the ones that have been posted in the thread or use one that is tailored for this dictionary, like:

use strict; use warnings; my $word = shift || 'OLHOSC'; my $fname = sprintf 'length%02d.txt', length $word; # eg. length06.tx +t my $word_key = join '', sort split //, lc $word; # sort lowercase +letters open my $fh, '<', $fname or die "sorry, no such word list available, +Bye!"; while( my $line = <$fh> ) { chomp $line; my $dict_key = join '', sort split //, lc $line; print "$word => $line\n" if $dict_key eq $word_key # bail out here - if only one match is needed } close $fh;

From the *length* of the looked-up word, the name of the dictionary file is built. If you extracted the above archive, then the files with word lengths between 2 and 32 should reside in the current directory.

Regards

mwa

Replies are listed 'Best First'.
Re^2: Found a word from a set of letters
by vnpenguin (Beadle) on Jan 29, 2008 at 19:22 UTC
    Thank you for your suggestion, Regards,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://664958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-25 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found