如何使用Perl将连接数据线转换为方案块?

时间:2010-05-03 14:59:03

标签: perl graph

我正在寻找一种将信号连接转换为简单方案或图形的方法。

假设我有2个组件,其周围有2个线路/信号:

component A:
 input - S1
 output - S2

component B: 
 input - S2
 output - S1

这将是输入数据文件,输出将是一个方案,将其显示为2个区块,周围有连接线或插图。

我想知道在Perl的世界中是否存在这种实现。

2 个答案:

答案 0 :(得分:6)

听起来你想要graphviz图形生成器。

它是用C语言编写的,但有一个Perl接口:GraphViz

示例:

use GraphViz;
use File::Slurp qw(write_file);

my $g = GraphViz->new;
$g->add_node('componentA');
$g->add_node('componentB');
$g->add_edge('componentB' => 'componentA', label => 'S1');
$g->add_edge('componentA' => 'componentB', label => 'S2');

write_file('out.png', $g->as_png);

您可以加载输入数据并通过信号编号的散列跟踪组件连接,然后为每个数据调用add_edge

输出:

graphviz output http://img704.imageshack.us/img704/2624/outd.png

(标签是可选的)。

答案 1 :(得分:1)

比照。 Graph::EasyGraphViz