#!/usr/bin/perl -w use strict; use Tree::DAG_Node; my $vocabulary = Tree::DAG_Node->new; $vocabulary->name("vocabulary"); my $vehicles = Tree::DAG_Node->new; $vehicles->name("vehicles"); my $animals = Tree::DAG_Node->new; $animals->name("animals"); $animals->new_daughter->name("domestic"); $animals->new_daughter->name("wild"); ($animals->daughters)[0]->new_daughter->name("dog"); ($animals->daughters)[1]->new_daughter->name("tiger"); my $sciences = Tree::DAG_Node->new; $sciences->name("sciences"); $vocabulary->add_daughters($animals, $sciences, $vehicles); print "tree\n"; print map "$_\n", @{$vocabulary->draw_ascii_tree}; print "\ndump names\n"; print $vocabulary->dump_names; print "\nanimals and descendants\n"; print join(",", map {$_->name} $animals->self_and_descendants), "\n"; __END__ tree | /--------------+----------\ | | | /---------\ | | | | dump names 'vocabulary' 'animals' 'domestic' 'dog' 'wild' 'tiger' 'sciences' 'vehicles' animals and descendants animals,domestic,dog,wild,tiger #### my $lol =$vocabulary->tree_to_lol; my $code =$vocabulary->tree_to_lol_notation({multiline=>1}); print "$code\n"; __END__ [ [ [ [ 'dog' ], 'domestic' ], [ [ 'tiger' ], 'wild' ], 'animals' ], [ 'sciences' ], [ 'vehicles' ], 'vocabulary' ],