in reply to Re: How to match and transform a multiline pattern?
in thread How to match and transform a multiline pattern?

I think I know what you are saying, but my mental block is with how to get the four lines in the first place. Since these lines are being read one at a time from a file, how would I know when to read more than one? Are you suggesting that I read the whole file in to a single string and do substitutions on the whole thing?
  • Comment on Re^2: How to match and transform a multiline pattern?

Replies are listed 'Best First'.
Re^3: How to match and transform a multiline pattern?
by apl (Monsignor) on Apr 20, 2007 at 18:19 UTC
    Two thousand lines of text is not a great deal.
    If you did treat it all as a single string, you could do a single $a =~ s/p/r/g;, changing all occurrences of the pattern p to r in buffer a.
      Agreed - 2000 lines is not large at all. I just sucked in the whole file and was able to convert it successfully using $a =~ s/p/r/g;.
      Thanks so much.
        Congratulations. And here I was about to post this boring screed on a Finite State Automata that would allow you to read one line at a time while learning if you had a four-line statement that was interesting ... 8-)