<?xml version="1.0" encoding="windows-1252"?>
<node id="1017269" title="Re: How to make buckets of like data" created="2013-02-05 15:07:28" updated="2013-02-05 15:07:28">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;Am I missing something simple here? &lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;I don't believe you can do it in one pass. This works, but might be simplified?:&lt;code&gt;
#! perl -slw
use strict;
use Data::Dump qw[ pp ];

my  @array = (['A','B'],['C','D'],['A','C'],['E','F'],['F','G']);
my %h;

for( @array ) {
    my( $x, $y ) = @$_;
    $h{ $x }{ $y } = 1;
    $h{ $y }{ $x } = 1;
}

OUTER:
for my $x ( reverse sort keys %h ) {
    for my $y ( reverse sort keys %h ) {
        next if $x eq $y;
        if( exists $h{ $y }{ $x } ) {
            $h{ $y }{ $_ } = 1 for keys %{ $h{ $x } };
            delete $h{ $x };
            next OUTER;
        }
    }
}

my @buckets = map[ sort keys %{ $h{ $_ } } ], keys %h;
pp \@buckets;

__END__
C:\test&gt;1017261
[["A", "B", "C", "D"], ["E", "F", "G"]]
&lt;/code&gt;


&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1017261</field>
<field name="parent_node">
1017261</field>
</data>
</node>
