in reply to Find anagrams

From dictionary.com: A word or phrase formed by reordering the letters of another word or phrase, such as satin to stain.

In case you played with this, and couldn't make it work, you have to feed it the word list, complete with anagrams. I.e., you can't supply 'stain', and have it find 'satin'. Rather, both words have to be present, and each word must be on a separate line.

It will also only print one of the anagrams, not all, so you have no way of referencing them. I.e., if you have 'satin', 'stain', and 'naits' (it's not a word...), only 'naits' will be printed. I'm not sure how exactly that's useful...

Some sample input would have been nice.

--Chris

e-mail jcwren

Replies are listed 'Best First'.
RE (tilly) 2: Find anagrams
by tilly (Archbishop) on Sep 21, 2000 at 00:38 UTC
    If it only prints one anagram then that is a bug in your version of Perl. It most certainly prints correctly on both Linux and Windows NT with Perl 5.005_03.

    As for input, throw your dictionary at it and see what you get...

      Well, it appears there are two problems. One is that it's O/S intolerant, and doesn't handle files with CR/LF. The other is that if a word occurs twice (like 'for') it prints 'for for'.

      The first problem was caused by using NOTEPAD.EXE to save some text I cut and pasted from a website to test it.

      Nonetheless, example programs *should* have some sample input and output. After all, if it was a "bug in your version of Perl", how would I know what to expect if it worked?

      --Chris

      e-mail jcwren
        Neither problem is a problem. On Windows your version of Perl should read by default as a text file and it will be fine. In Unix binary and text works fine. The only issue is if you read a DOS file in Unix, in which case I would trust no script not specifically designed to do that. (My production ones are though.) As for "for" and "for" working, the spec said find anagrams. Not find unique anagrams. The program works according to what my co-worker specified.

        As for the input, output issue, mea culpa.