Re: How to change Perl's concept of a newline in regexps?



R Krause schreef:
Dr.Ruud:
R Krause:

I know that $/ is the input record separator. But that doesn't seem
to affect any change in the behavior of regular expressions in
normal and multi-line mode.

That is the wrong way around. When (line oriented) input is read, and
the proper IO-layer is used, the resulting string will have a "\n" at
the end.
See also Encode::Encoding. Compare the :crlf layer.

Thanks. I've checked the :crlf layer but it seems to only work with
overall reading or writing operations and does not affect Perl's
internal processing of specific regexps (esp. in multi-line mode).

The :crlf layer normalizes the data, so that you don't need to use \r\n
in your code (regexp or not) if your text file happens to be one with
CRLF line endings.
Maybe there exists a :cr layer for Mac-type text files?


In
cases of network communications, it is often valuable to test some
portion of input presuming line-delimiters such as '\r\n' or even '\0'
using regular expressions, but to then leave other portions of the
transmission unchanged.

Of course, but make a distinction between platform-dependant line
oriented operations, and buffer oriented operations.


I'm still looking into Encode::Encoding, but that module seems very
complex just for processing text with alternate line-delimiters. :) I
guess the convenience of $ and ^ is lost in this situation, so one
needs to just roll his own.

If you are not reading the data in a line-oriented way, than just use \r
(or \x0D) etc. You can make your own zero-width assertions like (?=\r).

--
Affijn, Ruud

"Gewoon is een tijger."

.