Without knowing the contents of $self->{children} or the side-effects/return values of $node->traversal()
Presumably, traversal traverses a tree. The children of a node are likely of the same type as that node, which makes traversal a recursive function.
I cannot provide any additional insight.
The OP's first snippet returns the nodes of the tree in pre-order.
The OP's second snippet is obviously broken, traversing the entire tree to get only the nodes of depth one and two.
In reply to Re^2: map & arrays & recursion
by ikegami
in thread map & arrays & recursion
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |