|Don't ask to ask, just ask|
recursive complex structure or something like that?by Isanchez (Acolyte)
|on Jul 26, 2003 at 02:06 UTC||Need Help??|
Isanchez has asked for the
wisdom of the Perl Monks concerning the following question:
Dear Monks, I have a dataset that contains vocabulary entries such as:
The first number in the column is a unique index for the word. The second indicates the parent category represented by some other word that it belongs to. So, terrier has the unique index 3, but it is a type of dog so its parent id is the unique Id of dog i.e. 2. Collie is another type of dog, it has the unique id 4 and since it is a dog too its parent is also 2. fox terrier is a type of terrier, so its parent is the index of terrier 3.
In the actual file there are categories that have up to 17 levels in depth. The root term, i.e. the highest node in the hierarchy is "vocabulary" and has 12 immediate doughters. I have an input such as the one above and I have to come up with an output that will have all their descendant terms. Something like:
domestic_animal dog, terrier, collie, fox_terrier, cat, chesire_cat
I imagine that a recursive function is needed to keep collecting doughter terms. and the structure in which they have to be stored is probably a hash of arrays.
Can anyone lead me at least to a begining or some piece of code, algorithm to do this?