#! /usr/bin/perl -w use strict; my @words = <>; chomp(@words); &find_anagrams(@words); # Takes a list or words, finds all anagrams in it sub find_anagrams { my %anagrams; foreach my $word (@_) { my $key = join '', sort(split(//, lc($word))); push @{$anagrams{$key}}, $word; } foreach my $lst (values %anagrams) { if (1 < @$lst) { print "@$lst\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Find anagrams
by runrig (Abbot) on Sep 21, 2000 at 02:34 UTC | |
by jcwren (Prior) on Sep 21, 2000 at 04:52 UTC | |
|
(jcwren) RE: Find anagrams
by jcwren (Prior) on Sep 21, 2000 at 00:07 UTC | |
by tilly (Archbishop) on Sep 21, 2000 at 00:38 UTC | |
by jcwren (Prior) on Sep 21, 2000 at 01:00 UTC | |
by tilly (Archbishop) on Sep 21, 2000 at 02:50 UTC | |
|
RE (tilly) 1: Find anagrams
by tilly (Archbishop) on Sep 21, 2000 at 00:00 UTC | |
|
RE: Find anagrams
by acid06 (Friar) on Sep 21, 2000 at 05:40 UTC |