fireartist has asked for the wisdom of the Perl Monks concerning the following question:
and put it into a mysql table in the following format.cat1 cat1,sub1 cat1,sub1,sub-sub1 cat1,sub2 cat2 cat3 cat3,sub1
I know there's a maximum of 6 'tab's at the start of any line, so there's a maximum of 7 levels of categories.------------------------------------ | id | name | parent | ------------------------------------ | 1 | cat1 | 0 | | 2 | cat1,sub1 | 1 | | 3 | cat1,sub1,sub-sub1 | 2 | | 4 | cat1,sub2 | 1 | | 5 | cat2 | 0 | | 6 | cat3 | 0 | | 7 | cat3,sub1 | 6 | ------------------------------------
Then 'walk' it in some such way as,my @x = ('cat1', ['cat1,sub1', ['cat1,sub1,sub-sub1'], 'cat1,sub2'], 'cat2', 'cat3', ['cat3,sub1'], );
and somehow assign those id/parent variables.$x[0] is SCALAR 1/0 (id/parent) $x[1] is ARRAY $x[1][0] is SCALAR 2/1 $x[1][1] is ARRAY $x[1][1][0] is SCALAR 3/2 $x[1][1][1] isn't defined $x[1][2] is SCALAR 4/1 $x[1][3] isn't defined $x[2] is SCALAR 5/0 $x[3] is SCALAR 6/0 $x[4] is ARRAY $x[4][0] is SCALAR 7/6 $x[4][1] isn't defined $x[5] isn't defined
|
|---|