in reply to Matching words based on letter content

What I would do is take each word, split up the letters, and sort them alphabetically. Then you have a hash key which will be the same for "top", "pot", and so on. Here is an example.

use strict; use Data::Dumper; my @words = qw/opt top pot pit tip/; my %count; foreach my $w(@words) { my $key = join '', sort split '', $w; $count{$key}++; } print Dumper \%count;

Output:

$VAR1 = { 'opt' => 3, 'ipt' => 2 };

Update: Added the D::D output.

Replies are listed 'Best First'.
Re^2: Matching words based on letter content
by knirirr (Scribe) on Jan 28, 2005 at 15:22 UTC
    What I would do is take each word, split up the letters, and sort them alphabetically. Then you have a hash key which will be the same for "top", "pot", and so on. Here is an example.
    D'oh!
    It is rather simple when you think of it that way - thanks.