On 11/8/07, C. R. <[EMAIL PROTECTED]> 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?
You can't change what "\n" means, but it's not too hard to put CRLFs into your output. Here's the commonest way: my $CRLF = "\x0d\x0a"; print "There was a young lady... tut, tut!$CRLF"; print "So you think that you're in for some smut?$CRLF"; print "Some five-line crescendo$CRLF"; print "Of lewd innuendo?$CRLF"; print "Well, you're wrong. This is anything but...$CRLF"; print " --Stanley J. Sharples$CRLF"; For what may or may not be extra convenience, consider using the special variable $\ to automatically output your newline of choice after each invocation of print. http://perldoc.perl.org/perlvar.html I hesitate to mention this last alternative, but you could post-process the output instead of fixing the source. That would only be suitable if the source code is large and complex to update -- that is to say, source code so complex that applying s#\\n#\$CRLF#g to it would be a step in the wrong direction. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/