T
Tore Aursand
Hi!
I need to convert a large text file with indented data into a tree (ie.
into a child-parent relationship).
The text file looks like this:
Page 1
Page 1.1
Page 1.1.1
Page 1.1.2
Page 1.2
Page 1.3
Page 2
Page 2.1
I know that for each "level", there are a known number of spaces (in this
case 4), or 0 spaces if we're on a root level.
For each line I want to assign an incremental counter, so that I should
end up with an array of arrays representing the tree. For the example
above the array would look like this:
@array = (
[1,0], # Page 1
[2,1], # Page 1.1
[3,2], # Page 1.1.1
[4,2], # Page 1.1.2
[5,1], # Page 1.2
[6,1], # Page 1.3
[7,0], # Page 2
[8,7], # Page 2.1
);
I guess you'll get the idea. I'm totally stuck on this one, and I would
like some help from you guys (and girls).
Thanks in advance!
I need to convert a large text file with indented data into a tree (ie.
into a child-parent relationship).
The text file looks like this:
Page 1
Page 1.1
Page 1.1.1
Page 1.1.2
Page 1.2
Page 1.3
Page 2
Page 2.1
I know that for each "level", there are a known number of spaces (in this
case 4), or 0 spaces if we're on a root level.
For each line I want to assign an incremental counter, so that I should
end up with an array of arrays representing the tree. For the example
above the array would look like this:
@array = (
[1,0], # Page 1
[2,1], # Page 1.1
[3,2], # Page 1.1.1
[4,2], # Page 1.1.2
[5,1], # Page 1.2
[6,1], # Page 1.3
[7,0], # Page 2
[8,7], # Page 2.1
);
I guess you'll get the idea. I'm totally stuck on this one, and I would
like some help from you guys (and girls).
Thanks in advance!