in reply to Moving data in a tree

The first step is to get your tree into a data structure. Then you (recursively) traverse it, and for each node that contains one leave you delete that, and attach it to the root node.

And yes, perl is perfectly suitable for that.

If you have more specific questions, ask them. And once you've started to write perl code, show us what you have when you need more help.

Replies are listed 'Best First'.
Re^2: Moving data in a tree
by wade (Pilgrim) on Jul 21, 2008 at 20:56 UTC

    Interesting. I'd have done this a little differently. When you are traversing the tree and you are done processing a node, check to see if it only has one leaf. If so, move the single leaf to its parent node (deleting children that have no leaves). The end result would be the same (i.e., branches with single leaves would get moved to the root) but this would allow nodes that wouldn't make it all the way to the root to be propagated as high as they could be.

    Of course, that's not what the OP actually requested so I could be full of...er, um...I could be wrong.

    --
    Wade
      Would it be possible to load the excel file as is, then run the perl script on it?

        In general, if I don't have a memory crisis, I'd:

        • read the whole file into a suitable data structure,
        • manipulate the data structure, and
        • write the data structure out to a new file.

        That makes things easier to code and, since you have before and after files, easier to check.

        --
        Wade