in reply to Specific Regex with Multilines (/s and /m): Why Doesn't This Work?

Did you undefine the input record separator i.e. "undef $/;". If this is not the case you would be trying to match a multiline regex (i,e, your example chunk has 7 lines), but only reading the file line by line. So obviously the match would fail as you are comparing a single line with a pattern that expects more than one line.

Naturally in that case you have to use //s. Also the while loop has to change so that it loops as long as you find something with the regex, the file itself is read only once

  • Comment on Re: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?
  • Download Code

Replies are listed 'Best First'.
Re^2: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?
by onelesd (Pilgrim) on Jul 18, 2011 at 19:55 UTC
    If the HTML files are not so large as to create a RAM issue, read the entire file into a scalar and:
    $myHTML =~ s#<TR VALIGN="TOP">[\r\n]*(?:<TD><FONT SIZE="-1"></FONT></T +D>[\r\n]*){7}</TR>##g ;
    Then process $myHTML.
Re^2: Specific Regex with Multilines (/s and /m): Why Doesn't This Work?
by elvenwonder (Initiate) on Jul 19, 2011 at 14:23 UTC

    Ah, the undef $/; is what I was missing on the multiline search. The problem now is that I need to return it to it's default behavior in order to perform the rest of my regular expressions properly. I find it frustrating that Google won't allow me to search for "$/". Thank you jethro (et al).

      local $/; within the appropriate scope is almost always more useful than undef $/;.