in reply to grep using regex

Hi xing,

Your code is working fine with this given input. But you need to use flip-flop operator very carefully.

For example, if there is a file and we want to process only certain sections of it, then using the flip-flop operator the code can be written like:

while () { if (/!! START !!/ .. /!! END !!/) { # process line } }

Each time around the loop, the current line is checked by the flip-flop operator. If the line doesn't match /!! START !!/ then the operator returns false and the loop continues. When we reach the first line that matches /!! START !!/ then the flip-flop operator returns true and the code in the if block is executed. On subsequent iterations of the while loop, the flip-flop operator checks for matches again /!! END !!/, but it continues to return true until it finds a match. This means that all of the lines between the "!! START !!" and "!! END !!" markers are processed. When a line matches /!! END !!/ then the flip-flop operator returns false and starts checking against the first regex again.