I hate meetings.
Slight variation that I was working on before having to attend a meeting. Use add_path rather than add_edges
use strict;
use Graph;
use Graph::Undirected;
my $ud = Graph::Undirected->new();
while(<DATA>)
{
my @items = split(' ');
if(@items <= 1)
{
$ud->add_vertex(@items);
}
else
{
$ud->add_path(@items);
}
}
foreach my $connectedSet ($ud->strongly_connected_components)
{
print "Connected Nodes: " . join(',', @$connectedSet) . "\n";
}
__DATA__
a b c d e
f b g
h i j k l
m f
z
Update: Modified code based on feedback. Have to handle the case where there is only one letter on a line. UNFORTUNATELY this cause it to lock on strongly_connected_components call.
"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.
OSUnderdog
|