On Nov 8, 2007, at 9:33 PM, C.R. wrote:
I run a script on unix Perl to write a text file. By default, when
Perl
writes "\n" it writes a line ending sequence which is native to the
current OS. How do I force this particular script to always write DOS
CRLF line endings?
A good approach is to hard-code CRLF:
my $CRLF = "\015\012";
and then output that by hand the same way you would append "\n":
print "foo bar baz$CRLF";
You don't mention the runtime platform. If you are sure the runtime
platform uses Unix line-ending conventions you're done. If you need
the script to be portable or don't want to leave there that brittle
assumption you need to work in binmode.
Otherwise, since CRLF has a LF, on Windows you'd end up having triple
CRCRLF on disk, because the I/O layer translates LF -> CRLF on writing
no matter the surrounding characters.
Even if I weren't the author :-) I'd add a pointer to this article:
Understanding Newlines
http://www.onlamp.com/pub/a/onlamp/2006/08/17/understanding-newlines.html
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/