Wagner, David --- Senior Programmer Analyst --- WGO wrote:
-----Original Message-----
From: C.R. [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 08, 2007 12:34
To: beginners@perl.org
Subject: Writing DOS CRLF via Unix Perl
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?
$/ is the input rcd separator
$\ is the output rcd separator
You can set as want them to be if other than the std defaults
are desired for a particular processing.
If you have any problems or questions, please let me know.
Unfortunately this doesn't solve the problem David. The value of $\
is printed after every call to print (not printf), as a sort of implicit
last parameter. By default it is undefined and nothing extra is output,
but setting it to "\n" has exactly the same effect as explicitly printing
a newline: an appropriate line terminator is output according to the
platform.
If linefeed is expressed in hex as "\x0A" it won't be interpreted as a line
terminator and will be output untranslated to the stream. This can be used
independently or in conjunction with $\.
Alternatively, setting a stream to binmode will also prevent "\n" from being
translated, but this is a less desirable solution as it implies things about
the output that are untrue.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/