use strict; use warnings; my @data = ( [ 1,3 ], [ 1,4 ], [ 1,5 ], [ 3,8 ], [ 3,9 ], [ 4,11 ], [ 4,18 ], [ 8,14 ], [ 8,15 ], [ 5,17 ], [ 5,16 ], [ 17,21 ], ); use Tree::Simple; my %nodes; foreach my $edge ( @data ) { my ($parent_id, $child_id) = @$edge; my $parent = $nodes{$parent_id} ||= Tree::Simple->new( $parent_id ); my $child = $nodes{$child_id} ||= Tree::Simple->new( $child_id ); $parent->addChild( $child ); } use Tree::Visualize; my $visualize = Tree::Visualize->new( $nodes{1}, 'ASCII', 'TopDown' ); print $visualize->draw(), $/, $/; use Tree::Simple::View::ASCII; my $tree_view = Tree::Simple::View::ASCII->new( $nodes{1} ); $tree_view->includeTrunk(1); print $tree_view->expandAll(), $/, $/; __END__ | +---+ | 1 | +---+ ________________|___________________ | | | +---+ +---+ +---+ | 3 | | 4 | | 5 | +---+ +---+ +---+ ___|________ ____|____ ____|____ | | | | | | +---+ +---+ +----+ +----+ +----+ +----+ | 8 | | 9 | | 11 | | 18 | | 17 | | 16 | +---+ +---+ +----+ +----+ +----+ +----+ ____|____ | | | | +----+ +----+ +----+ | 14 | | 15 | | 21 | +----+ +----+ +----+ 1 |---3 | |---8 | | |---14 | | |---15 | |---9 |---4 | |---11 | |---18 |---5 |---17 | |---21 |---16