in reply to Re: multiline regex: heredoc vs. reading file
in thread multiline regex: heredoc vs. reading file

One line? From page 147 of 'Programming Perl' -

/m Let ^ and $ match next to embedded \n.
/s Let . match newline and ignore deprecated $* variable.

Wouldn't that mean it would look for multiple lines?

  • Comment on Re^2: multiline regex: heredoc vs. reading file

Replies are listed 'Best First'.
Re^3: multiline regex: heredoc vs. reading file
by ysth (Canon) on Jan 25, 2006 at 18:06 UTC
    /m changes where ^ and $ can match; /s changes what . can match. Since you don't have any of ^, $, or . in your regex, the flags do nothing.

    The problem is that you have a regex that only matches multiple lines, but you are trying to match each line of the file against it individually, and of course none of them do match.

Re^3: multiline regex: heredoc vs. reading file
by ikegami (Patriarch) on Jan 25, 2006 at 18:02 UTC
    The problem is not with the regexp. The problem is that $_ only contains one line. See my earlier post in this discussion for more details.
      OK, so I changed the while loop to contain the following, and still get the same thing -
      $_ .= <TEST>; if (m{ \w+\n .+ \w+ }msx) { print "reading file test: The line \n$_\nmatches.\n"; }
      I would think that
      a) $_ .= <TEST>; would be equivalent to your $text = <$test_fh>; line, and
      b) replacing \n with .+ utilizes the /s,

      correct?

        Now, $_ contains two lines, but you need three with the data you showed. Also, $_ .= <TEST> could attempt to read past the end of the file, but you don't check for that.