You're calling an object method without constructing the object.

From your description, it sounds like you want a complete graph for the vertices listed in each element of list1.

use Graph::Undirected; my @colors = qw( black white red green blue cyan magenta yellow); my @combos = ( [qw(black cyan yellow)], [qw(red white blue)], [qw(white blue)], [qw(green red)], [qw(cyan magenta)], [qw(yellow magenta)], [qw(magenta cyan)], [qw(magenta black yellow)], ); my $g = Graph::Undirected->new(@colors); for my $combo (@combos) { # Special case of all @$combo <= 3, the following # can be replaced by: # $g->add_cycle( @$combo); for my $pick (0..$#$combo-1) { $g->add_edge( $combo->[$pick], $combo->[$_]) for $pick+1..$#$ +combo; } } my @components = $g->strongly_connected_components; print "@$_", $/ for @components;
That adds all the elements of list2 as vertices in the constructor, then adds edges for all pairs in each element of list1. Is that close to what you want?

Update: Repaired a couple of typos and a harmless fencepost error in the inner loop which added self-edges to most vertices. Added comment with simpler code for the case that the @combos elements don't have more than three colors. In response to glwtta's reply, modified data to exhibit disconnected components and added component extraction code with the &Graph::Base::strongly_connected_components method. The Graph module has lots of methods like this, documented in Graph::Base

After Compline,
Zaxo


In reply to Re: using Graph::Undirected by Zaxo
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.