in reply to Re: strip out lines until match
in thread strip out lines until match

Yes, it's a string, so I ought to be able to do what you suggest... however that regexp doesn't seem to match my string. I threw together the following to test it:

$string = " blah @QUERY meaningful data meaningful data ... etc... @ENDQUERY @QUERY2 more data more data ... etc ... @ENDQUERY2"; print "string1: $string\n\n"; $string =~ s[(?:\r?\n\s*)+(\@QUERY)][\n$1]g; print "string2: $string\n\n";'

And my output is something like this. Can you help me tweak the regexp?

string1: blah meaningful data meaningful data ... etc... more data more data ... etc ... string2: blah meaningful data meaningful data ... etc... more data more data ... etc ...

Thanks,

AH

P.S. bart I'm looking at ".." and it seems very powerful... I may end up using it, once get my head around it.

----------
Using perl 5.6.1 unless otherwise noted. Apache 1.3.27 unless otherwise noted. Redhat 7.1 unless otherwise noted.

Replies are listed 'Best First'.
Re: Re: Re: strip out lines until match
by BrowserUk (Patriarch) on Apr 16, 2004 at 14:15 UTC

    If you turned "use strict" on, you'd see the problem.

    string = " blah @QUERY meaningful data meaningful data ... etc... @ENDQUERY @QUERY2 more data more data ... etc ... @ENDQUERY2"; Possible unintended interpolation of @QUERY in string at (eval 1) line + 1, <> line 16. Possible unintended interpolation of @ENDQUERY in string at (eval 1) l +ine 1, <> line 16. Possible unintended interpolation of @QUERY2 in string at (eval 1) lin +e 1, <> line 16. Possible unintended interpolation of @ENDQUERY2 in string at (eval 1) +line 1, <> line 16.

    Replace the "s with 's when you initialise $string and you will see the correct result.

    Also, as Enlil points out elsewhere in the thread, my regex was more complex than necessary. It can be replaced with s[\s+(\n\@QUERY)][$1]g;.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

      Yeah, I can't believe I missed that. Just goes to show that you can't ever afford to skip "use strict", even in a simple script.

      Thanks to everyone for their help. Now if you'll excuse me, I have to go write "use strict" 1000 times on the blackboard.

      AH

      ----------
      Using perl 5.6.1 unless otherwise noted. Apache 1.3.27 unless otherwise noted. Redhat 7.1 unless otherwise noted.