Jeremy Bopp wrote in post #1053841:
> On 03/28/2012 04:25 PM, Jan E. wrote:
>>   file.print *lines
>> end
>>
>> Yeah, this *is* ugly. I wonder why Ruby cannot handle that itself.
>
> In Ruby 1.9, which the OP is using, File.readlines /can/ handle this
> better.  You can specify the mode in which to open the file directly as
> a hash option.

Using #readlines to copy a file identically is the wrong tool IMHO.

> Or is the solution "ugly" because you have to manually specify binary
> mode when opening files?

I'd rather do it with blocks of fixed length for efficiency reasons:

File.open "oldf.txt", 'rb' do |io_in|
  File.open "newf.txt", 'wb' do |io_out|
    buffer = ""

    while io_in.read(1024, buffer)
      io_out.write(buffer)
    end
  end
end

But what about the dups?  What constitutes a duplicate?  If it is just
raw content, you could use "sort -u" (standalone command).

Kind regards

robert

-- 
Posted via http://www.ruby-forum.com/.