Fletch is correct; by your own description, the only code that you posted is not the even the code that produces the warning. Please post more details. Often, when reducing large code to a concise example of a problem, you will find the solution yourself.

That said, I can see a few possible problems.

  1. You mention Graph::Undirected, which implies that your graphs should be undirected, but your example code uses Graph->new(), which creates *directed* graphs.
  2. Graph::Writer::Dot does not correctly handle undirected graphs; it treats them as if they were directed. This will not produce any warning; it will just cause GraphViz to render the graph's edges with arrows. My casual testing indicates that this simple patch will correct the problem:
    --- Graph/Writer/Dot.pm_original Fri Jun 14 01:54:05 2002 +++ Graph/Writer/Dot.pm Mon Nov 15 10:31:35 2004 @@ -68,13 +68,15 @@ my %attributes; my @keys; + my $arrow = ($graph->directed) ? '->' : '--'; + my $gname = ($graph->directed) ? 'digraph' : 'graph'; #---------------------------------------------------------------- +--- # If the graph has a 'name' attribute, then we use that for the # name of the digraph instance. Else it's just 'g'. #---------------------------------------------------------------- +--- $gn = $graph->has_attribute('name') ? $graph->get_attribute('name +') : 'g'; - print $FILE "digraph $gn\n{\n"; + print $FILE "$gname $gn\n{\n"; #---------------------------------------------------------------- +--- # Dump out any overall attributes of the graph @@ -114,7 +116,7 @@ while (@edges > 0) { ($from, $to) = splice(@edges, 0, 2); - print $FILE " $from -> $to"; + print $FILE " $from $arrow $to"; %attributes = $graph->get_attributes($from, $to); @keys = grep(exists $attributes{$_}, @{$valid_attributes{'edge'}} +); if (@keys > 0)
  3. You may be using the wrong syntax to invoke methods on the objects stored in the %graph hash. Here is a working example program, to demonstrate the syntax:
    #!/usr/bin/perl use warnings 'all'; use strict; use Graph::Undirected; use Graph::Writer::Dot; my @areas = qw( America Britain Chile ); my @verts = qw( Phone_Company Cellular_Networks Government Internet Rural_Users ); my %graph; # Hash of Graph::Undirected objects. foreach my $area (@areas) { $graph{$area} = Graph::Undirected->new(); $graph{$area}->add_vertex($_) foreach @verts; } $graph{America}->add_edge(@verts[0,1]); $graph{America}->add_edge(@verts[1,2]); $graph{America}->add_edge(@verts[3,0]); $graph{America}->add_edge('Government', 'Internet'); $graph{Britain}->add_edge(@verts[0,2]); $graph{Britain}->add_edge(@verts[1,2]); $graph{Britain}->add_edge(@verts[3,2]); for ($graph{Chile}) { $_->add_edge(@verts[0,1]); $_->add_edge(@verts[0,2]); $_->add_edge(@verts[0,3]); $_->add_edge(@verts[1,2]); $_->add_edge(@verts[1,3]); $_->add_edge(@verts[2,3]); } my $writer = Graph::Writer::Dot->new(); foreach my $area (@areas) { $writer->write_graph($graph{$area}, "$area.dot"); }


In reply to Re: creating multiple graphs programmatically by Util
in thread creating multiple graphs programmatically by Anonymous Monk

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.