in reply to I still can't get only the necessary lines from the file.

in your text file example you have Start context and * Exit context *
in your code you're matching for START context and End context
I modified the code to match correct, tested, and works fine:
will print everything except what your matching for in the print unless
open (DATA,"<c://xxx.txt") || die "Can't open xxx.txt: $!\n"; while(<DATA>) { if (/Start context/ .. /\* End Context \*/) { print unless /(Start context|\* Exit context \*)/; } }

Replies are listed 'Best First'.
Re^2: I still can't get only the necessary lines from the file.
by sashac88 (Beadle) on Jul 01, 2004 at 07:19 UTC
    Oops -my mistake.I have the correct line in my code's unless. \* Exit context \*
    The problem is that in print results I get lines that are not between the closest "Start context" and "* end context *".
    I suspect that maybe the problem is in this line:
    if (/Start context/ .. /\* End Context \*/)
    which IMHO takes all the lines between the first "Start context" in the file and last "* end context *"
    . Am I right? Or the line:
    if (/Start context/ .. /\* End Context \*/)
    looks for the closest "Start context" and "* End context *"
    Thanks
      The .. "flip-flop" operator (see perlop) is true "between" the two operands. That is, once the left-hand match is true, the flip-flop is true, until whenever the right-hand match succeeds. Then it's false until the left-hand match is true, and so on.

      So, no: if (/Start context/ .. /\* End Context \*/) { doesn't "take" "all the lines between the first 'Start context' in the file and last '* end context *'", but indeed only those within any of the contexts (and the start marker too, but not the end marker).