From: "Wagner, David --- Senior Programmer Analyst --- 
> > -----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.


You'd better not. Fiddling with those GLOBAL variables can break a 
lot of modules expecting them to have their default values.
You should only modify $/ in a small block and make sure you do not 
call any function that might want to read anything from a file or 
socket or pipe or ...
And you should not fiddle with $\ as it affects all print() 
statements. Not just those going to your file. Besides it doesn't 
convert \n in the middle of a printed string to CRLF ... all it does 
is that it prints a CRLF (or whatever you set it to) after each 
print. So this

print HANDLE "First line\nSecond line";
print HANDLE "Third line";

causes the file to contain (on unix) 

  First lineLFSecond lineCRLFThird lineCRLF

Again you are very likely to break things by changing $\.

It's better to specify that you want the \n -> CRLF conversion for 
that particular filehandle:

   open OUT, '>:crlf', 'the_file.txt';

HTH, Jenda

===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to