On Thu, 27 May 2004 00:14:57 -0500, Jim Witte wrote: > Given a file of words W such as 'cat dog at home ...' > and a set of letters L 'aoeuidhtns' > how would I write a program to extract all words in W whose letters > are all in L?
Here is an overview that should get you going: Split L with an empty regular expression. That will give you an array A of all characters in L. Take the array A and create a hash H out of it. Each item of A is a hash key. Use whatever you want as hash value, Read a line M from the file that contains words W. Split the line M with a Regular Expression that will return you an array with all words in M into array B. Loop over all words in B. In the loop you will split the word with an empty regular expression. This will create an array C of all characters of the word in B. Loop over all the items in C and see if they exist in the hash H. If you get a negative report you exit the loop and go to the next word. If you get a positive report you add the word B to an array or to a file. At the end of the loop go back to reading in a line M... and loop, until no further line is found. Sorry, I had a bit to much fun with the naming style of the original question. thanks /oliver/ -- "If you believe everything you read, you better not read." -Japanese Proverb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>