in reply to Pattern Matching

...My friend now wants to see more context...

you mean friend as in teacher? ;-)

Anyway, this question has been asked just a few days ago and you will probably be able to find it. But as you surely want to do your homework yourself, you should:

  • match against the pattern and print the previous line (from the variable where you stored it, see next bullet) and the current line
  • store the current line in a variable, so that you can print it in the next while-iteration if necessary
  • pull the next line from <File> and print it (but only if you matched)


    Regards,
    svenXY

    update: and don't forget to use strict and warnings as suggested by ++Crian. In addition, you might want to check if your input isn't something dangerous...

  • Replies are listed 'Best First'.
    Re^2: Pattern Matching
    by lostjimmy (Chaplain) on Nov 19, 2008 at 15:54 UTC
      You also have to take into account when two lines match in a row. What do you do then? Do you still print the previous line, even though it was already printed?