I have a text file with on every line a magic card number and such info
eg: 072 GTC U Mental Vapors
I'm trying to read the file line for line and append each line to a file named foozled.txt.
I wrote a method to_s it prints to screen right with output :
072 |GTC| U | Mental Vapors
but I need this output to append this to the foozled file.
how can this be done?
it now prints nil on each line in the foozled file
------------> snipped code
File.open(cardList,"r") do |file|
file.each_line {|line| line.length
parse=Card.new("#{line}","#{line}","#{line}","#{line}")
File.open('foozled.txt','a') do |line| line.puts parse.to_s #appends only nil to the file but prints to screen
end
}
end
On 04/29/2013 07:34 PM, tamouse mailing lists wrote:
On Apr 29, 2013 4:37 PM, "Joel Pearson" <lists@ruby-forum.com > <mailto:lists@ruby-forum.com>> wrote:
>
> Or you could do the whole operation with a single read, string
> processing, and a single write
This can be a problem if the source file is large, but certainly, yes.
well, ok, that would have meant opening, appending a line and closing it
17,000 times in the original. it is sometimes hard to conceive of computers
doing actual work, but that is a lot of unnecessary opens and closes.
otoh, 17,000 lines may not costbthat much ram if read in all at one time,
filtered to a buffer, and appended en masse. so joel does have a point.
a billion lines is more into the problem space of too much to buffer. (or
in the case i am familiar with, 4GB database file)
···
On Apr 29, 2013 6:38 PM, "peteV" <pete0verse@gmail.com> wrote:
On 04/29/2013 07:34 PM, tamouse mailing lists wrote:
On Apr 29, 2013 4:37 PM, "Joel Pearson" <lists@ruby-forum.com> wrote:
>
> Or you could do the whole operation with a single read, string
> processing, and a single write
This can be a problem if the source file is large, but certainly, yes.