### Comment on

 Need Help??

Hello.

With hash of hash, for looking ups.

```#!/usr/bin/perl
use strict; use warnings; use Data::Dumper;
my @a=(1,1,2,3,4,4,8,8);
my @b=(3,4,3,5,6,7,9,10);
my \$hoh={};

for ( 0 .. \$#a){
\$hoh->{\$a[\$_]}->{\$b[\$_]}++;
\$hoh->{\$b[\$_]}->{\$a[\$_]}++;
}
sub recursive {
my (\$hoh, \$key, \$path, @vals) =@_;
for ( grep { \$_ ne \$key } @vals){
next if exists(\$path->{\$_});
\$hoh->{\$key}->{\$_}++;
\$path->{\$_}++;
recursive(\$hoh, \$key, \$path, keys %{\$hoh->{\$_}} );
}
}
for (sort {\$a <=> \$b}keys %\$hoh){
recursive(\$hoh, \$_, {}, keys %{\$hoh->{\$_}} );
}

#print Dumper \$hoh;
for (sort {\$a <=> \$b}keys %\$hoh){
print "\$_=" , join(",", keys %{\$hoh->{\$_}}), "\n";
}

__DATA__
this prints ...
1=6,4,3,7,2,5
2=6,4,1,3,7,5
3=6,4,1,7,2,5
4=6,1,3,7,2,5
5=6,1,4,3,7,2
6=1,4,3,7,2,5
7=6,1,4,3,2,5
8=10,9
9=8,10
10=8,9
And as BillKSmith points out, if you take this as a graph,
```#!/usr/bin/perl
#with graph
use strict; use warnings; use Data::Dumper;
use Graph;
my \$g =Graph::Undirected->new;

my @a=(1,1,2,3,4,4,8,8);
my @b=(3,4,3,5,6,7,9,10);

for ( 0 .. \$#a){
}
print Dumper \$g->connected_components;
__DATA__
this prints ...\$VAR1 = [
9,
8,
10
];
\$VAR2 = [
6,
4,
1,
3,
2,
5,
7
];
regards.

In reply to Re: to find inter connected items by remiah
in thread to find inter connected items by Janaki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [erix]: going for a run in the dunes - unless the storm (well, Beaufort 7) gets fiercer Discipulus had stew with tomato sauce, onions, carrots and potatoes + bottle of red wine and still warm bred.. slept as dynosaur

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2017-11-22 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (316 votes). Check out past polls.

Notices?