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

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.
  • Comment on Re^4: Detect line endings with CGI.pm upload

Replies are listed 'Best First'.
Re^5: Detect line endings with CGI.pm upload
by gwadej (Chaplain) on Dec 28, 2008 at 20:55 UTC

    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

      Not true.

      >perl -le"print length qq{\n}" 1 >perl -le"print unpack 'H*', qq{\n}" 0a

      In Perl, LF gets converted to CRLF on input/output when the crlf PerlIO layer is used. While the string is in memory, you want to work with just LF, and \n is just LF.