use warnings; use strict; use Tree::Simple; # make a tree root my $tree = Tree::Simple->new("0", Tree::Simple->ROOT); while(<DATA>) { chomp; my ($child, $parent) = split /:/; my $sub_tree = Tree::Simple->new("$parent", $tree); # explicity add a child to it $sub_tree->addChild(Tree::Simple->new("$child")); } $tree->traverse(sub { my ($_tree) = @_; print (("\t" x $_tree->getDepth()), $_tree->getNodeValue(), "\n"); }); __DATA__ apple:fruit granny smith:apple fuji:apple orange:fruit blood orange:orange mandarine:orange dwarf fuji:fuji
Currently, the output looks like this:
$ perl test.pl fruit apple apple granny smith apple fuji fruit orange orange blood orange orange mandarine fuji dwarf fuji
I want a format more like the one in the module example:
1 1.1 2 2.1 2.1a 2.2 3
I know I am missing some stuff, but I can't grok it. :(
In reply to Re^3: Creating a tree from a parent child list, that also includes node specific properties...
by bryank
in thread Creating a tree from a parent child list, that also includes node specific properties...
by bryank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |