Multi line pattern matches? 
Author Message
 Multi line pattern matches?

  I am trying to determine if a form has been completely filled out using perl 4. I open the file then look at each line in a while loop, looking for the original (ie not fileld in) questions, to flag an error if one is found. For example,

  while (<FILE>) {
...
    /Evaluation(\s+)____(\s+)____(\s+)____(\s+)____(\s+)____/ &&
      return "Evaluation";
...

  Where the evaluation question is multiple choice, and one of the blanks is supposed to be filled in. If none of the blanks is filled in I return an error.

  The problem is in the open ended questions, such as "What do you think of Madonna?". I simply want to make sure that something is filled in. Ideally I would like to do the following inside the while loop:

     /Open ended question number 1\?(\s*)^Open ended question number 2/ &&
       return "open ended question #1";

  Ie If the only thing between question #1 and #2 is whitespace, then the question has not been filled in and should return an error.
  The problem is that inside a while (<FILE>) loop, $_ will only be a single line, so multi-line messages like the above are not possible (the pattern will never match).
  I am trying to avoid doing something like looking for question #1, keeping state that question #1 was found, and flagging an error if question #2 is found. I really don't want to resort to state variables running around everywhere.

  Can anyone suggest a way to do this?

Denny Gentry



Sat, 09 Mar 1996 14:18:09 GMT  
 Multi line pattern matches?
:   I am trying to determine if a form has been completely filled out using perl 4. I open the file then look at each line in a while loop, looking for the original (ie not fileld in) questions, to flag an error if one is found. For example,
:
:   while (<FILE>) {
: ...
:     /Evaluation(\s+)____(\s+)____(\s+)____(\s+)____(\s+)____/ &&
:       return "Evaluation";
: ...
:
:   Where the evaluation question is multiple choice, and one of the blanks is supposed to be filled in. If none of the blanks is filled in I return an error.
:
:   The problem is in the open ended questions, such as "What do you think of Madonna?". I simply want to make sure that something is filled in. Ideally I would like to do the following inside the while loop:
:
:      /Open ended question number 1\?(\s*)^Open ended question number 2/ &&
:        return "open ended question #1";
:
:   Ie If the only thing between question #1 and #2 is whitespace, then the question has not been filled in and should return an error.
:   The problem is that inside a while (<FILE>) loop, $_ will only be a single line, so multi-line messages like the above are not possible (the pattern will never match).
:   I am trying to avoid doing something like looking for question #1, keeping state that question #1 was found, and flagging an error if question #2 is found. I really don't want to resort to state variables running around everywhere.
:
:   Can anyone suggest a way to do this?

You could undef $/ and slurp in the whole file, then pick it apart as
you please.  I doubt the typical form is going to gobble up your
address space, so a slurp solution is in order here.

Alternately, you can insert a known token between questions, and then set
$/ to that token, assuming you can trust the user not to modify the token,
or that you can have the forms system insert them somehow before calling you.
Then each <FILE> input would contain an entire question, not just a line.
(You also have to guarantee that the token is not going to occur in anyone's
answer.)

Larry



Mon, 11 Mar 1996 01:07:57 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Multi-line pattern matching?

2. Multi-line pattern matching

3. Multi line pattern match

4. Multi-line pattern matching in 5.001n

5. Pattern bug matching whitespace in multi-line match?

6. regex to match a multi line pattern

7. pattern matching in multi-line strings fails under perl4.034

8. regex to match a multi line pattern

9. Can't Match Multi-Line Pattern

10. multiline, multi pattern match

11. Multi-Inclusive Pattern Match

12. "Multi-line" patterns

 

 
Powered by phpBB® Forum Software