Mac CR \015 \x0D \r
DOS CRLF \015\012 \x0D\x0A \r\n
*Nix LF \012 \x0A \n
(Assuming \r is chr(13) and \n is chr(10), which isn't always true)
The regex to substitute them all would be s/\cM|\cM\cJ|\cJ/$foo/, which can be simplified to s/\cM\cJ?|\cJ/$foo/. But if you don't need to substitute, removing can be done a lot faster by just using tr/\cM\cJ//d (the /d will have tr/// delete characters not found in the replacement pattern (the replacenent pattern is empty in this example)).
2;0 juerd@ouranos:~$ perl -e'undef christmas'
Segmentation fault
2;139 juerd@ouranos:~$
| [reply] [d/l] |
| [reply] |
| [reply] [d/l] |
No, no, no!! $/ will be "\n" by default on Windows, just
like it is (nearly?) everywhere else!
-
tye
(but my friends call me "Tye")
| [reply] |
| [reply] [d/l] |
I'm not a big fan of the documentation you quoted. It
muddles the distinction between processing of "\n" during
I/O operations and the value of "\n" in a Perl string.
This muddling helps lead to the confusion that we see
several places in this thread.
"\n" is "\cJ" on nearly all platforms even though writing
it to an I/O handle doesn't produce (just) "\cJ" on many
platforms. "\n" could be any single character on a non-ASCII
system. On an ASCII system, "\n" is "\cJ" except on (some?)
Mac systems. But on Win32, writing "\n" actually sends
either "\r\n" or "\n" depending on whether binmode is in
effect. On VMS (which is an ASCII system, BTW), writing
"\n" might not write any data to the file (but instead
result in meta-data that denotes where the record ends), it
all depends on the "structure" of the file in question
(most files on VMS are not simply "streams").
-
tye
(but my friends call me "Tye")
| [reply] |
| [reply] |
Or, if you're sure no \ns or \rs will appear in the middle of lines, you can do it even more simply:
split /[\n\r]+/, ...
| [reply] [d/l] |