in reply to Re: Detect line endings with CGI.pm upload
in thread Detect line endings with CGI.pm upload

If you don't have to worry about old Macs, you don't have to worry about running on old Macs, so you can get away with
s/\r?\n/\n/g
or just
s/\r(?=\n)//g

Replies are listed 'Best First'.
Re^3: Detect line endings with CGI.pm upload
by gwadej (Chaplain) on Dec 26, 2008 at 23:06 UTC

    I remember a thread here recently pointing out that \n is not guaranteed to be a line feed, and that the suggested approach approach was to use \x0a and \x0d because you can be sure of their meanings.

    I vaguely remember having that problem way back when I was a C programmer.

    G. Wade
      The only system where \n and \r aren't LF and CR is MacPerl (Perl for old Macs). This has nothing to do with C.

        On Windows \n is CRLF, not LF, even in C. This can cause problems when reading and writing files that shold be binary but are written as text and vice versa.

        Update: as ikegami correctly points out, I was conflating the disk version with the in memory version of these strings. \n should always be the line feed (in memory) and the I/O subsystem should have converted it.

        G. Wade