Generoso has asked for the wisdom of the Perl Monks concerning the following question:
Hi Dear Monks,
I am tring to parse a tree with tree::parser,
the data is as follows:
Where format is parent => childrenList of hash table: 16098 => 16078 => 16101 16015 => 16022, 16033, 16047, 16074, 16090 16029 => 16003 16097 => 16035 16057 => 16052 => 16001 => 16015, 16023, 16026, 16027, 16058, 16110 16101 => 16089 16007 => 16104 => 16020, 16059, 16069, 16078, 16088 16014 => 16024, 16046, 16098 16105 => 16000 => 16066, 16116 16087 => 16085 16074 => 16002, 16043, 16109 16053 => 16051, 16092, 16099 16037 => 16041, 16102 16036 => 16056 => 16005, 16112 16093 => 16075, 16083 16111 => 16016, 16025, 16039, 16053, 16091 16100 => 16019, 16073, 16107 16042 => 16035 => 16082 => 16031 16004 => 16114 => 16081 16033 => 16106 16010 => 16072 => 16064 16084 => 16088 => 16027 => 16097 16116 => 16007, 16095 16113 => 16110 => 16050, 16056, 16067, 16082, 16111 16090 => 16008, 16114 16026 => 16005 => 16024 => 16080 => 16054 16003 => 16051 => 16025 => 16054 => 16002 => 16060 16916 => 16076 16070 => 16102 => 16063 16044 => 16060 => 16063 => 16089 => 16062 => 16055 => 16052 16075 => 16069 => 16113 16040 => 16030 16034 => 16017, 16018, 16049 16012 => 16064 => 16043 => 16086 16013 => 16085 => 16079 => 16099 => 16067 => 16077 => 16108 16032 => 16062 16066 => 16001, 16014, 16037, 16072, 16093, 16104 16045 => 16107 => 16029, 16080 16011 => 16012 16059 => 16112 => 16106 => 16079 16094 => 16028 16083 => 16038, 16042, 16045, 16105 16049 => 16004, 16013 16092 => 16061 => 16010 16030 => 16038 => 16031 => 16039 => 16047 => 16077 16021 => 16016 => 16081 => 16020 => 16009, 16048 16009 => 16041 => 16073 => 16040 16095 => 16017 => 16916, 16103 16108 => 16050 => 16023 => 16034, 16055, 16100 16076 => 16006 => 16058 => 16032, 16071, 16094 16086 => 16091 => 16006, 16057 16019 => 16084 16046 => 16028 => 16044 16008 => 16087, 16096 16071 => 16070 16103 => 16109 => 16061 16018 => 16011, 16068 16048 => 16096 => 16068 => 16022 => 16021, 16036
How can I give this as input to use Tree::Parser; # create a new parser object with some input my $tp = Tree::Parser->new($input);
What I was really trying to do is a recursive function. my $fv = fact ('16000'); my $level = 0; my $ord = 0; sub fact { my $val = $_[0]; my $ch = $hash{$val}; my @chs = split(',',$ch); print ' 'x$level x 3,$val," ",$_[0]," ",$level," ",$ord++,"\n"; if ($ch) { $level++; foreach my $ch1(@chs){ fact($ch1); delete $hash{$ch1}; } $level--; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of Tree::Parser
by graff (Chancellor) on May 26, 2010 at 04:36 UTC | |
by Generoso (Prior) on Jun 01, 2010 at 22:30 UTC | |
|
Re: Use of Tree::Parser
by Khen1950fx (Canon) on May 26, 2010 at 06:02 UTC |