Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

creating multiple graphs programmatically

by Anonymous Monk
on Nov 10, 2004 at 15:17 UTC ( #406684=perlquestion: print w/replies, xml ) Need Help??
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 (Chancellor) 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:

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://406684]
Approved by Courage
Front-paged by Courage
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-10-24 12:22 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (289 votes). Check out past polls.