I am using the Tree::Nary module in a Perl program of mine in which I recently added a recursive function, recurse_tree.
I am finding that each time I call recurse_tree, an empty node, containing no data, is being added to my N-ary tree.
I need to traverse the children of parent nodes using Tree::Nary->children_foreach. To allow Tree::Nary->children_foreach to take each node in the {children} linked list as input I have had to include within my recurse_tree function the following wrapper function:
my $call_recurse_tree = sub {
my $node = shift;
&recurse_tree($node);
};
Which is used used by Tree::Nary->children_foreach as follows:
# PROCESS CHILDREN LIST: recurse_tree will be called on each
+child of the input Dir Node
Tree::Nary->children_foreach($node, $Tree::Nary::TRAVERSE_ALL
+, $call_recurse_tree);
Empty nodes are being added to my N-ary tree in recurse_tree, even though neither this function nor its helpers calls any Tree::Nary append or prepend function -- yet empty, bogus nodes are somehow getting into my tree, one for each call to recurse_tree.
Has anyone ever had a similar problem with Tree::Nary? Could my workaround "my call_recurse_tree = sub" be the culprit? What really makes this problem maddening is that both recurse_tree and its helpers are receiving the node of the N-ary tree BY VALUE, not BY REFERENCE, so they ought not to be able to change my actual N-ary tree -- they are only working on local copies of this tree.
Thank You,
Amphiaraus
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.