Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Reading a File by Line then Analyzing each Lineby soon_j (Scribe) |
on Jun 06, 2006 at 16:29 UTC ( [id://553858]=perlquestion: print w/replies, xml ) | Need Help?? |
soon_j has asked for the wisdom of the Perl Monks concerning the following question:
Monks, I am faced with a task of reading a text file line by line, then analyzing each line. The "reading" part of the file by line is easier, but the "analyzing" part is what troubles me. This is a sample of my text file: 1. What is my name? A. Rooney * B. Gerrard C. Ronaldo D. Ronaldinho 2. Who's your bet in the coming World Cup? A. Brazil * B. Germany C. England D. Cameroon My code for reading each line goes like this: In the above example, if: $tmp = "1. What is my name?" How will I match the "number" until it encounters a "period", discard this portion and assigns the remaining part to: $question = "What is my name?" Same goes for this also: $tmp = "A. Rooney *" How will I match the "letter" until it encounters a "period", discards this portion and assigns the remaining part to: $choice_a = "Rooney *" Also if it encounters "*" at the end of the choices, it removes this "*" and declares this as the answer: Example: $choice_a = "Rooney *" (becomes $choice_a = "Rooney" after "*" is removed) $choice_b = "Gerrard" $choice_c = "Ronaldo" $choice_d = "Ronaldinho" $answer = "Rooney" Please bear with me as I am not good is regular expressions, matching, etc.
Back to
Seekers of Perl Wisdom
|
|