Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to print/draw a network graph

by GrandFather (Saint)
on Jun 30, 2006 at 02:21 UTC ( #558498=note: print w/replies, xml ) Need Help??


in reply to Re: How to print/draw a network graph
in thread How to print/draw a network graph

Following a little egging on and a simple example from blokhead (my thanks for that!) the following code generates the graph I was after. Note that this code uses dot from GraphViz.

use warnings; use strict; my @lines = <DATA>; my @splitLines = map {[/'(....)'..([-\d]*)\) -> '?(....)'?..([-\d]*)/] +} @lines; my $graphStr = <<GRAPH; digraph G { graph [rankdir=LR]; node [shape=rect]; GRAPH $graphStr .= " $_->[0]$_->[1] -> $_->[2]$_->[3]\n" for @splitLines; $graphStr =~ s/-(?!>)/_/g; $graphStr .= "}\n"; open outFile, '>', 'graph.dot'; print outFile $graphStr; close outFile; `dot -Tpng -ograph.png graph.dot`; __DATA__ 'TAvi' (-37) -> 'TDMk' (-32) 'TAvi' (-38) -> 'TMrk' (-34) 'TDMk' (-32) -> xfer (-12) 'TDif' (-7) -> xfer (-11) 'TDif' (-8) -> 'TMCF' (-35) 'TDig' (-27) -> 'TSpN' (-33) 'TLCI' (-36) -> 'TAvi' (-37) 'TMCF' (-35) -> 'TLCI' (-36) 'TMrk' (-34) -> xfer (-28) 'TSpN' (-33) -> 'TAvi' (-38) 'TSpN' (-33) -> 'TDMk' (-32) 'TSpN' (-33) -> 'TMCF' (-35)

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://558498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-05-25 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?