in reply to store parent child relation

This is tested and works, assuming the format is the same as what you said (just a single line of numbers separated by commas in each file). You'll need to change the path for opening files, though, and if this is for homework (which seems likely), you'll want to rewrite the code and make sure you understand all of it.
use strict; use warnings; use Data::Dumper; my $tree = build(1); print Dumper($tree); my @arr = traverse($tree); print "@arr"; sub traverse { my $p = $_[0]; return ($p->{'key'}, map { traverse($_) } @{$p->{'branches'}}); } sub build { my (%node, $key, @branches, $handle); $key = $_[0]; $node{'key'} = $key; $node{'branches'} = \@branches; if (open ($handle, "$key.txt")) { chomp($_ = join '', <$handle>); close($handle); for (split /,/, $_) { push @branches, build($_); } } return \%node; }

Replies are listed 'Best First'.
Re^2: store parent child relation
by Anonymous Monk on May 18, 2006 at 08:37 UTC
    TedPride,
    Thanks a lot for excellent code and help.