[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

force file write in dos format

Martin DeMello

9/1/2007 11:17:00 AM

Is there any built-in way to force File.puts to use dos line endings,
regardless of the platform under which the program is running?

martin

3 Answers

Martin DeMello

9/1/2007 12:42:00 PM

0

On 9/1/07, Felix Windt <fwmailinglists@gmail.com> wrote:
>
> Use IO#print instead of IO#puts and set $\, the default output record
> separator:

Thanks!

martin

Xavier Noria

9/2/2007 12:53:00 AM

0

On Sep 1, 2007, at 1:16 PM, Martin DeMello wrote:

> Is there any built-in way to force File.puts to use dos line endings,
> regardless of the platform under which the program is running?

If I undertand correctly what you want your program is going to
explicitly output pairs "\r\n".

If that's the case, in addition to the recommendation about IO#print
already given take into account that the io needs binmode. Otherwise,
on CRLF platforms you'd end up with "\r\r\n" on disk, which would be
wrong. That's because the single "\n" in "\r\n" gives itself a pair
"\r\n" in text mode. So IO#print CRLF in binmode is the complete
portable solution.

-- fxn


Martin DeMello

9/2/2007 8:17:00 PM

0

On 9/2/07, Xavier Noria <fxn@hashref.com> wrote:
> On Sep 1, 2007, at 1:16 PM, Martin DeMello wrote:
>
> > Is there any built-in way to force File.puts to use dos line endings,
> > regardless of the platform under which the program is running?
>
> If I undertand correctly what you want your program is going to
> explicitly output pairs "\r\n".
>
> If that's the case, in addition to the recommendation about IO#print
> already given take into account that the io needs binmode. Otherwise,
> on CRLF platforms you'd end up with "\r\r\n" on disk, which would be
> wrong. That's because the single "\n" in "\r\n" gives itself a pair
> "\r\n" in text mode. So IO#print CRLF in binmode is the complete
> portable solution.

Good point. As of now this will only ever be run on a linux box, but
it certainly doesn't hurt to future-proof it.

martin