Hi All, I am trying to sort some data, which originally came as an excel file.
There are main titles, sub titles, sub sub titles and sub sub sub titles. They defined by using different levels of indents in the original file. I parse it and convert indents into spaces. Main titles are sorted by first letters, but sub titles are not. I need to sort all of them in their own groups as in the following example: (I put comments starting with an asterisk to make my question more clear.) ------------------------------ Original file: 0 Apple 0 Book 0 Color 1 Red 1 Green 2 Tree 0 School 1 Collage 1 University 2 Zakulty 2 Faculty 3 Maculty 3 Aculty 2 Bus 1 Elementary Output that I need. 0 Apple 0 Book 0 Color 1 Green * G < R 2 Tree 1 Red 0 School 1 Collage 1 Elementary * E < U 1 University 2 Bus * B < F|Z 2 Faculty 3 Aculty * A < M 3 Maculty 2 Zakulty -------------------------------- I am trying to put them into arrays and try cmp $a<=>$b. 12 while (<$file>) { 13 chomp(); 14 my ($tab, $title) = split ("\t", $_); 15 if ($tab eq "0") { 16 17 $main[$f] = $title; 18 $f++; 19 $g = "0"; 20 21 } 22 elsif ($tab eq "1") { 23 $sub[$f][$g] = $title; 24 $g++; 25 $h = 0; 26 } 27 elsif ($tab eq "2") { 28 $sub2[$g][$h] = $title; 29 $h++; 30 $i = 0; 31 } 32 elsif ($tab eq "3") { 33 $sub3[$h][$i] = $title; 34 $i++; 35 } 36 } this strategy works for only if there are main and sub titles. it doesn't work for 2. and 3. level sub titles, because of the change of 1. level sub title array. "putting them into different files with a coding to indicate their upper level titles, and later put them into arrays like push ( @{$sub[3]}, (Red, Green) ) order them, and use this coding to put them under main titles" might be helpful . But it will be confusing to me. main.txt: 1 Apple 2 Book 3 School sub.txt 3 1 Collage 3 2 University sub2.txt 3 2 1 Faculty or not flat files but using mysql with perl? ( one table with cols for each sub level, 'if's and for loops with ORDER BY of Mysql ). 3 0 0 0 School 3 2 0 0 University 3 2 1 0 Faculty So, have you got an idea or is there a known way to make this task easier? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/