japhy has asked for the wisdom of the Perl Monks concerning the following question:
Right now, I've got a bunch of data structures, but I don't know how to allocate this data into the "islands" of related domains. The word island is used because, when this is all done, the groups of domains will not have two values in common with any other groups.
My data structures are:
#!/usr/bin/perl use strict; use warnings; chomp(my @fields = split /\t/, <>); my (%domains, %links, %rel, %group); shift @fields; while (<>) { chomp; my ($dom, @values) = split /\t/, $_, -1; @{ $domains{$dom} }{@fields} = @values; } my @dlist = my @domain_list = keys %domains; while (@dlist) { my $d1 = shift @dlist; for my $d2 ($d1, @dlist) { $links{$d1}{$d2} = [ grep { $domains{$d1}{$_} eq $domains{$d2}{$_} and $domains{$d1}{$_} ne "" and $domains{$d1}{$_} ne "Private, Registration" and $domains{$d1}{$_} ne "Domains by Proxy, Inc." and $domains{$d1}{$_} !~ /^DomainsByProxy.com/i } @fields ]; } } for my $d1 (@domain_list) { $rel{$d1} ||= $d1; $group{ $rel{$d1} }{$d1} = 1; for my $d2 (grep { @{ $links{$d1}{$_} } > 1 } keys %{ $links{$d1} }) + { $rel{$d2} ||= $d1; $group{ $rel{$d2} }{$d2} = 1; } } for my $d1 (sort { keys(%{ $group{$b} }) <=> keys(%{ $group{$a} }) } k +eys %group) { print "GROUPED TO $d1\n"; for my $d2 (sort keys %{ $group{$d1} }) { print " $d2 (via: @{ $links{$d1}{$d2} })\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Building "islands" of related data
by jfroebe (Parson) on Dec 08, 2005 at 17:46 UTC | |
Re: Building "islands" of related data
by Tanktalus (Canon) on Dec 08, 2005 at 17:50 UTC | |
Re: Building "islands" of related data
by BrowserUk (Patriarch) on Dec 09, 2005 at 01:02 UTC | |
by japhy (Canon) on Dec 09, 2005 at 16:18 UTC | |
Re: Building "islands" of related data
by TedPride (Priest) on Dec 09, 2005 at 00:19 UTC | |
Re: Building "islands" of related data
by Ryszard (Priest) on Dec 09, 2005 at 11:09 UTC |