Tree::Simple may be a good module for certain specialized tasks, but you can create and manipulate all the trees you like by using plain hash references. It's straightforward and much more readable for other perl developers.
Creating a tree from a file can be easy as:
use strict; use warnings; my $lookup; while(my($parent, @children) = <DATA> =~ /(\S+)\s*/g) { $lookup->{$parent} ||= []; push @{$lookup->{$parent}}, @children; } sub build { my $children = delete $lookup->{+shift} || []; my $parent = {}; $parent->{$_} = build($_) for(@$children); return $parent; } my $tree = build('ROOT'); use Data::Dumper; print Dumper $tree; __DATA__ ROOT a b c b e f a d
This code will build a nice tree of hashrefs and the input reading code nearly matches what you want. It'll even read the input regardless of how the lines are ordered.
I found the following tutorials for you:
andIn reply to Re: Using Tree::Simple with while loop and input file.
by mzedeler
in thread Using Tree::Simple with while loop and input file.
by bryank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |