James Gray
6/22/2005 8:47:00 PM
On Jun 22, 2005, at 3:40 PM, Erik Veenstra wrote:
>
> If I run these scripts on Linux (replacing "dir" with "ls -l")
> the outputs are what I expect. Both scripts print 5 and show a
> file size of 5. But when I run them on Windows... Surprise,
> surprise... The file sizes become 6! A hex editor tells me that
> there are 2 CR's: 61 62 63 0D 0D 0A.
>
> Why?
In Ruby (and Perl), \n is symbolic in meaning, representing the
platforms standard line ending. Thus on Windows, \n translates to \r
\n. You are adding an extra \r.
You can shut off this translation behavior by opening the file in
"binmode" (add a "b" to the file mode string).
Hope that helps.
James Edward Gray II