I think this is more of an algorithm question, not perl tho very
interesting to do it in perl.
I am not gr8 in algorithms , but this is what I will do
Write a function that will return all the letters sorted in a word
For eg for the word home , return ehmo
sub wkey {
my(@l)=sort split(//,$_[0]);
return join("",@l);
}
# Create a hash array where the keys are all possible combinations of
# the letters in the string 'L' with the letters in each key sorted
# alphabetically.
# For eg if your string is "abc"
# $L="abc";
# %hash = ( a=>1,b=>1,c=>1,ab=>1,ac=>,bc=>1,abc=>1);
#
# How to do it ? That will be your homework :-)
#
open(FILE,"W") || die "$!";
$/=" "; # Now read the file and read one word at a time
while(<FILE>){
s/\s+//g; # Get rid of all whitespace
if($hash{wkey($_)}) {
print "This word '$_' exists in the string\n";
}
}
__END__
I hope someone in this group can give you a better algorithm
HTH
Ram
On Thu, 2004-05-27 at 10:44, Jim Witte wrote:
> Given a file of words W such as 'cat dog at home ...' (or perhaps read
> into an array, though that would be a very large array), and a set of
> letters L (a string 'aoeuidhtns' - perhaps put into a array), how would
> I write a program to extract all words in W whose letters are all in L?
> I'm thinking of a program to generate a string of words for a
> typing-tutor program.
>
> Jim Witte
> [EMAIL PROTECTED]
> Indiana University CS
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>