Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: how to construct tree from parent pointer list

by bryank (Acolyte)
on Jun 30, 2009 at 14:18 UTC ( #776039=note: print w/replies, xml ) Need Help??


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:

my @nodes = $tree->traverse( $tree->PRE_ORDER );
The example I was working off of:

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 (Pope) on Jun 30, 2009 at 15:49 UTC

    The module does provide an example for output,

    The module's traverse is useless in most circumstances since it provides a flat list.

    Basically, I didn't know what to do since I couldn't find a tree object?

    Every node is a Tree object.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://776039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-11-26 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?