|Welcome to the Monastery|
Re: adding 0D 0A to a UTF-8 file.by elef (Friar)
|on Feb 23, 2011 at 16:53 UTC||Need Help??|
I'm not sure what you really want to do here (why generate some output with a perl script and then copy-paste it into a file instead of just generating the final file with perl?), but here's some info:
The squares you see are definitely not the Windows line ending, which all Notepad versions display correctly as a line break (0D 0A, or, as perl coders tend to misleadingly call it, \r\n, or, as I like to call it, CRLF). It might be the Unix newline, i.e. LF, which Notepad can't handle and displays as a rectangle. Or it might be the old mac newline, CR.
BTW I'm sure the "arrows" you are seeing are just the opening and closing angle brackets of tags of some sort.
Perl always uses the platform's line ending as default, so, as you're running perl on Windows, the line ending generated by the line break character \n will be CRLF (this is why calling CR \r and calling LF \n is confusing: on Windows, \n generates CRLF, not just LF as it does on *nix).
Basically, if you use defaults on a file with Unix newlines on a Windows computer, you'll either generate a file with mixed LF/CRLF endings, or inadvertently convert the whole file to CRLF. The latter might actually be preferable to keeping it with LF, esp. if you'll open it with Notepad, but if you want to keep it with LF, you'll have to resort to trickery. Either redefine the newline character in your script or print LF "manually". Not sure how to do that, as this code seems to print CRLF on my computer:
...as do \012, \x0A and
As far as I understand, these should all produce a file with a Unix newline, but all tests show that the file actually has CRLF. I'm lost here, but I'm sure somebody will shed light on this.
Further reading: http://perldoc.perl.org/perlport.html#Newlines