linuser2 has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I've written a script that must add a newline to a text file that get's transferred from Linux to a NT 4.0 Server. I've tried char(10) and char(13) and "\n". they all appear as the block character in NT! I believe this has to do with Unicode? How do I print a newline that NT will understand??

Replies are listed 'Best First'.
Re: newline for Unicode?
by ahunter (Monk) on Jun 16, 2000 at 23:39 UTC
    All Unicode characters are 16 bits wide (well, not strictly true...), but have a large variety of encodings. In UTF-8, for instance, the ASCII characters are encoded exactly the same way, so newline is, er, \n. UTF-7 is just plain silly, and UTF-16 is 16-bits wide, so newline would be \0\n.

    (Note that the first 256 characters of Unicode are the ISO-8859-1, character set, better known as Latin-1. The first 128 are ASCII)

    There again, in NT, text files are plain 8-bit ASCII (with the top-bit set characters being some godawful M$ encoding), so \r\n should indeed do the trick, unless you really are using some form of Unicode editor & file format. (Perl was written for Unix, where newline is just \n, but NT considers newline to be \r\n. Actually, only notepad seems to think that these days...)

    Andrew.

Re: newline for Unicode?
by visnu (Sexton) on Jun 16, 2000 at 20:46 UTC
      yeah. windows thinks of a newline differently than unix, which thinks differently than macs. I found this out when dealing with webservers on different platforms.I wanted to split the return from a web request into the header and the http data.( the header is separated from the data by two newlines). So in order to make this work cross platform, i had to use this:
      my ($header , $data) = split (/\n\n|\r\n\r\n|\r\r/ , $result, 2);

      this handles unix newlines, \r\n (windows newline), and \r for the macs.
RE: newline for Unicode?
by Ovid (Cardinal) on Jun 16, 2000 at 20:58 UTC
    I've never used it, but I think that Unicode::Map might solve your problem. Check the read me. You'll also have to install Startup.pm (it's at the same link).