in reply to How to control UNIX vs DOS line feeds in Perl
Along the same line, if you FTP files from one OS to another, you do so using the ASCII protocol, which correctly adapts your text file's newlines to match the conventions of the other OS, so that tools on the new OS can correctly read the lines of your file. Again, if the new OS incorrectly uses conventions from your source OS instead of the newline conventions of the OS they're running on, that is anomalous behavior that should be corrected.
If you truly need Perl to treat a file as anything but a simple text file (allowing you to set your own newline conventions), you should use binmode and treat the file as a binary file:
If you do something like this, avoid \n, which literally means "newline", which will behave differently under different operating systems, counter to what you seem to want.binmode(FH); local $/ = "\cM\cJ"; # CRLF print FH "A line of pseudo-ASCII text$/"; while (<FH>) { # This might actually work, given that it honors $/ }
|
|---|