Forum: Ruby copy txt file - only copies 1/3 of the file - what happened?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cf63da956b6ba955687a2f2f262928cb?d=identicon&s=25 Mmcolli00 Mom (mmcolli00)
on 2008-12-11 04:42
File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
     m = f1.gets
     File.open('newFile.txt','w') do |f2| #newFile to separate data in
oldFile
     f2.puts m.split("<")
  end
end

Hello All.
There is something that I did that was weird here. I say this because
when I open the new file that it creates its 1/3 the size of the
original. It seems to just completely cut off. I took off the .split and
it still did this, so I know it has nothing to do with split. What do
you think is going on?

oldFile.txt
contains XML formatted data.

newFile.txt
is supposed to break each line up what starts with < giving a new line
per element for later use.
A61ecce13ed142622f24a5ca3a123922?d=identicon&s=25 Matthew Moss (Guest)
on 2008-12-11 04:47
(Received via mailing list)
On Dec 10, 2008, at 9:37 PM, Mmcolli00 Mom wrote:

> File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
>     m = f1.gets
>     File.open('newFile.txt','w') do |f2| #newFile to separate data in
> oldFile
>     f2.puts m.split("<")
>  end
> end


Perhaps replace line 2 with:

     m = f1.read

?
797ef431a5e1295b56c08e1db4c8d2df?d=identicon&s=25 botp (Guest)
on 2008-12-11 05:02
(Received via mailing list)
On Thu, Dec 11, 2008 at 11:37 AM, Mmcolli00 Mom <mmc_collins@yahoo.com>
wrote:
> File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
>     m = f1.gets

ok, this gets just one line of text fr f1

>     File.open('newFile.txt','w') do |f2| #newFile to separate data in
> oldFile
>     f2.puts m.split("<")

and you placed that one line on f2

>  end
> end

and that is all. you just copied one line.

hint: File.open by itself does not loop.
Cf63da956b6ba955687a2f2f262928cb?d=identicon&s=25 Mmcolli00 Mom (mmcolli00)
on 2008-12-11 05:10
Thanks for the help Matthew and Guest botp! It worked great.
This topic is locked and can not be replied to.