http://www.perlmonks.org?node_id=406684

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Graph::Base, Graph::Undirected, and Graph::Writer::Dot explore and visualize a large electrical network. I need to be able to create multiple graphs based on information in the (flat) source files. I need to do something like this:
foreach $area (@areas) { $graph{$area} = Graph->new(); }
I've tried all the tricks I can think of with no joy. I get warnings when I try to add a vertex or an edge, not when I create the graphs. I'm stumped. Any suggestions welcome.

Replies are listed 'Best First'.
Re: creating multiple graphs programmatically
by Fletch (Bishop) on Nov 10, 2004 at 15:39 UTC

    Your vreemflitzer's obviously clogged near the 3rd fetzer valve. Try Penzoil . . . no, make that Quaker State.

    (Maybe if you posted some actual code and the actual error messages you're getting someone could come up with something resembling a useful reply.)

Re: creating multiple graphs programmatically
by Util (Priest) on Nov 15, 2004 at 18:00 UTC

    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:
    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: