in reply to Re: Finding connected components in a graph.
in thread Finding connected components in a graph.

Hi there, As per your suggestion I added these two lines, but as you can see in the output section the results are totally invalid.
print "First connected component == $subgraphs[1]\n"; print "Number of connected components== $#subgraphs\n";
-----OUTPUT----------
5 ----connected components--------------- - - c - b - a - - e - d First connected component == ARRAY(0x9a8e308) Number of connected components== 1

Replies are listed 'Best First'.
Re^3: Finding connected components in a graph.
by SuicideJunkie (Vicar) on Oct 02, 2012 at 18:32 UTC

    Yes. The subgraph is an array reference. Dig in! foreach my element (@{ $subgraphs[0] }) {...}

    As expected, the last index in your two element array is 1. The other index is 0. As I wrote, you want to print 0+@subgraphs, or more explicitly, scalar(@subgraphs).