in reply to Re^3: how to construct tree from parent pointer list
in thread how to construct tree from parent pointer list
Thanks. The module does provide an example for output, but I couldn't figure out how to implement it in the example shown here. For example, here is what the module gives:
The example I was working off of:my @nodes = $tree->traverse( $tree->PRE_ORDER );
use Tree (); my %nodes; while (<>) { my ($child, $parent) = split /:/; my $parent_node = $nodes{$parent} ||= Tree->new($parent); my $child_node = $nodes{$child} ||= Tree->new($child); $parent_node->add_child($child_node); } my @roots = grep { $_->is_root } values %nodes; die("Invalid data: Multiple roots\n") if @roots > 1; my $root = $roots[0];
Basically, I didn't know what to do since I couldn't find a tree object? I'm sure I am missing all sorts of obvious signs in the code -- I am just too much of a newby to fully understand it. Sorry.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: how to construct tree from parent pointer list
by ikegami (Patriarch) on Jun 30, 2009 at 15:49 UTC |
In Section
Seekers of Perl Wisdom