Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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
[karlgoethebier]: no typo
[marioroy]: At the Fransiscan monastery, got stuck up high in a tree from pruning and the chainsaw with large branch fell and broke the latter, but not me fortunately. Was stuck there for a while until a firetruck came by.
[Corion]: marioroy: So you live dangerously ...
[Lady_Aleena]: s/latter/ladder/; # ? marioroy
[karlgoethebier]: marioroy: Praise the Lord
[marioroy]: Well, that's why there must be angels around, invisible or not.
[marioroy]: Lady_Aleena yes, ladder.
[marioroy]: Corion, no not intentionally. not at all.
[Lady_Aleena]: /ne tries to decide whther or not to take a hammer to hubby's alarm clock.
[Lady_Aleena]: He never hears it.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-05-29 08:36 GMT
Find Nodes?
    Voting Booth?