in reply to Re^2: print matching lines
in thread print matching lines

so are you looking for a match between # input 1 and another one? or between any 2 inputs? and, another important question, are all the inputs numerically ordered like that?


Remember rule one...

Replies are listed 'Best First'.
Re^4: print matching lines
by Anonymous Monk on Jul 10, 2005 at 20:06 UTC
    this is some code i have tried
    while (<FH>) { local $/ = '# input'; if (m/1ord/) { print $/, $_; } }
      Since the purpose of setting $/ (see http://perldoc.perl.org/perlvar.html#$/) is to change what <> reads, you need to have it set before the loop. while(<>) will still put the input in $_; don't expect $/ to change.

      Hint: try a simple loop:

      local $/ = "# input"; while (<FH>) { print "got record:\n", $_, ":end of record\n"; }
      then try to come up with a regex to match the records you want and print the appropriate thing. You'll need the //m flag.

      Another perfectly fine approach would be to leave $/ unchanged and save the line(s) you want to print, then print them if and when you get "ord".

      That will never match as there is no line with '1ord' in it.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re^4: print matching lines
by Anonymous Monk on Jul 10, 2005 at 19:49 UTC
    the # input line is not numerically ordered (just to illustrate). so the only match is for the line ord. if it does match then print the # input three lines above
      nothing to see here, move along, wrong post, waiting for the reaper.


      Remember rule one...