hackdaddy has asked for the wisdom of the Perl Monks concerning the following question:
However, having read through, in advance, gmax's tutorial A crash course on trees, I am itching to use the Tree::DAG_Node module to solve this problem. The stumbling block I am encountering is that I do not know how to take a data structure, such as tadman's in the code snippet above, and then programmatically create a Directed Acyclic Graph. With the tree constructed, I can then use the "walk_down" method with the callbackback option for a postorder scan.my @list = f( a => [ 'b', 'c' ], b => [ 'c', 'd' ], c => [ 'd' ], e => [ 'b', 'a' ], f => undef, ); sub f { $h{$_}||=[]for map@$_,%h=@_; sub x { my$x=1; $x+=x($_)for@{@h{@_}||[]}; $x } sort{x($a)<=>x$b}keys%h }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Creating a Dependency Tree Using the Tree::DAG_Node
by gmax (Abbot) on Jan 25, 2003 at 13:42 UTC |