Dec 4, 2012, 3:58 AM
Post #8 of 8
Aside from other problems, which we can discuss later, your script has the disadvantage, that it does not work for subsubsubsections. You should allow it for an arbitrary number of 'sub'.
You should do this by counting the number of occurances of the string 'sub' at the beginning of the string being read.
Here a general idea:
(1) Declare an array @current_section_number, which has the property that $current_section_number[$n] holds the current number of the section which has $n times the word 'sub' in its name.
(2) Open your input file
(3) For each line in the input file, update @current_section_number accordingly and print the section number for the file
You need to keep track of all section numbers simultaneously, because depending on the input, you will have to reset section numbers to 1 occasionally.
One more note: When developing your program, especially as a beginner, ALWAYS start your program with the following lines:
use warnings FATAL => qw(all);
Once you are experienced enough (i.e. you know what you are doing), you can adjust these lines according to your needs.