It would be nice if you gave us some sample input data. Here is how I imagine a more complete example would work:
use strict; use Graph::Undirected; use Data::Dumper; # Suppose list1 consists of the # edges to add. Lowercase is first # list, uppercase is second list. # a to A, B, C # b to C, D my @list1 = ( [ qw(a A) ], [ qw(a B) ], [ qw(a C) ], [ qw(b C) ], [ qw(b D) ]); my $g = new Graph::Undirected; foreach my $ids (@list1){ $g->add_path(@$ids); } $Data::Dumper::Indent = 1; print Data::Dumper->Dump([\$g], [qw(*g)]);
If I understand what you said you wanted to do, it would not make sense to have more than two items in each "add_path" call. That is, if you had [ qw(a A B C)] instead, there would be edges from a to A to B to C, which is wrong. You want a bipartite graph, correct?

Or perhaps you want something different. If you have an edge between every list2 vertex that shares an id, you would need not only A to B to C, but also C to A, a cycle. Please clarify your question with a more complete example.


In reply to Re: using Graph::Undirected by tall_man
in thread using Graph::Undirected by glwtta

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.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.