http://qs321.pair.com?node_id=699168


in reply to Moving data in a tree

There are various modules on CPAN that will help you a great deal.

With Tree::DAG_Node for instance you can traverse the tree, running methods or simply and safely pruning and splicing the leaves and branches of your tree as you go along.

Untested...

my @leaves = (); $root->walk_down('callback' => sub { if (!scalar($_[0]->daughters)) # is it a leaf? push @leaves, $_[0]; return 1; } $root->add_daughters(@leaves);