in reply to multi line matching problem

Rather than striping newlines, I'll try and answer your other question, about doing a "multiline matching expression". Do you know about the "s///ms" trick? Typically you use the m and s modifiers when working on a string with embedded newlines, one changes the meaning of . so that it also matches a /n, the other changes the meaning of ^ and $ so that they match the beginning and end of lines (most people I know use them both together and don't bother remembering which one does which...):
my $string = <<ENDSTRING; <thing> condition condition condition condition randomness other junk </thing> ENDSTRING print "$string\n"; $string =~ s{ <thing>.*?</thing> } {<THANG>blah</THANG>}msx; print "$string\n";
That should output:
 <thing>
 condition condition
   condition   condition
    randomness
      other junk
 </thing> 

 <THANG>blah</THANG> 
I'd recommend reading the "matching within multiple lines" recipe in the Perl Cookbook (that's recipe 6.6 in both the 1st and 2nd editions).

And by the way... you're not rolling your own code to parse HTML or XML are you? You should be looking for already existing modules out on CPAN.

Replies are listed 'Best First'.
Re: Re: multi line matching problem
by jcpunk (Friar) on Dec 16, 2003 at 08:33 UTC
    ah ha! In my foolish frustration I forgot about the perl cookbook and its wealth of useful data. Sadly I consulted google (with very poor search terms no less (shame upon me)) and when it turned up crap that wasn't helpful, I got lazy and posted to here - after checking the tutorials section.
    The "s///ms" trick is going into my working memory. I thank thee for pointing it out to me.
    In regards to the rolling my own code for parsing out html/xml, I sort of am, but not without good reason. The program in progress needs to have some files in html format for no terribly good reason (insert boss module) and so it shall be. And in regards to CPAN, lets just say an overly paranoid sysadmin stands between me and that alternative. I could of course go for the  use lib '/bla/foo/meh' option, but for other reasons too complex waste your time on, that also isn't workable (see site inconsistency).
    Ending rant before I realize what a crappy assignment I have and quit.

    Again thanks a lot for the help.


    jcpunk
    all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)
      Perl By Example (on-line)

      the Perl Cookbook (on-line).

      ...And then, He rested.:) NOTE: I AM HAPPY TO HAVING STUDIED FROM THE PERL BY EXAMPLE BOOK AT MY PUBLIC LIBRARY (you should also try your public library, you'ld be amazed! And it is always so quiet... And perhaps you find the Camel!).-

        Those have been bookmarked. Thank you very much.

        jcpunk
        all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)