<?xml version="1.0" encoding="windows-1252"?>
<node id="515509" title="Re: Building &quot;islands&quot; of related data" created="2005-12-09 06:09:21" updated="2005-12-09 01:09:21">
<type id="11">
note</type>
<author id="103344">
Ryszard</author>
<data>
<field name="doctext">
ok, so, if performance, speed, and anything good is not a problem to trample on, how about this:
&lt;code&gt;
#!/usr/bin/perl -w

use strict;
use Data::Dumper;
use Digest::MD5 qw(md5_hex);

# I want to group domains together if they share at least two of those values.
# The 1st two entires match, the 3rd not
my %domains = (
               'foo.com' =&gt; {
                           phone =&gt; '1234',
                           company =&gt; 'big co',
                           contact =&gt; 'john',
                           address =&gt; 'cool street',
                           fax     =&gt; '5678',
                           email   =&gt; 'john@bigco.com',
                          },
               'bar.com' =&gt; {
                           phone   =&gt; '2222',
                           company =&gt; 'small co',
                           contact =&gt; 'jeff',
                           address =&gt; 'bad street',
                           fax     =&gt; '5678',
                           email   =&gt; 'john@bigco.com',
                          },
               'baz.com' =&gt; {
                           phone   =&gt; '9999',
                           company =&gt; 'another co',
                           contact =&gt; 'judy',
                           address =&gt; 'nasty street',
                           fax     =&gt; '8888',
                           email   =&gt; 'frank@anotherco.com',
                          },
              );

# Build permutation hash
foreach my $domain (keys %domains) {

    # Iterate over all the elements in the domain hash
    foreach my $o_attr (keys %{$domains{$domain}}){

        # As we're creating hashes of each permutation we need to iterate
        # over the same elements
        foreach my $i_attr (keys %{$domains{$domain}}){

            $domains{$domain}{hash}{$o_attr}{$i_attr} = md5_hex(${$domains{$domain}}{$o_attr}.${$domains{$domain}}{$i_attr});

        }
    }

}

print Dumper(%domains);
&lt;/code&gt;
&lt;p&gt;You can then loop over all the permutations looking for hashes that match!&lt;/p&gt;</field>
<field name="root_node">
515307</field>
<field name="parent_node">
515307</field>
</data>
</node>
