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

this is some code i have tried
while (<FH>) { local $/ = '# input'; if (m/1ord/) { print $/, $_; } }

Replies are listed 'Best First'.
Re^5: print matching lines
by ysth (Canon) on Jul 11, 2005 at 01:08 UTC
    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".

Re^5: print matching lines
by CountZero (Bishop) on Jul 10, 2005 at 22:44 UTC
    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