in reply to Re: Perl code help
in thread Perl code help

Thanks Athanasius, this helped a lot. Also, I need one more help. What if the START and END tags are not as simple - it maybe starting with many spaces and instead of START - it will be
START STEP abc absbsdefdbdb ghi END STEP START STEP xyz abc END STEP
I need the same result to be generated

Replies are listed 'Best First'.
Re^3: Perl code help
by haukex (Archbishop) on May 29, 2016 at 11:31 UTC

    Hi usertest,

    What if the START and END tags are not as simple

    Did you try out the code that Athanasius posted above? Was the output as you expected it or not?

    The regular expressions that Athanasius used will match the words "START" and "END" anywhere in the line, so at least with this sample data you posted it works the same.

    why this statement $flag =~ /E0$/ and how it works

    This regular expression tests for a special value returned by the range operator in scalar context aka flip-flop operator: it marks the end of a range (see the link for all the details). That means that in this case, the condition is true when an "END" is encountered, then the code checks whether it $found a "def" string and acts appropriately, either printing the lines it captured or not.

    Hope this helps,
    -- Hauke D