ok so i''m trying to just read out a file line by line and i can''t seem to figure out how to not get an EOFerror... is there some way to tell when i get to the end of the file? i''m just reading out line by line, splitting it and sticking it in a database. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
file_out = File.new("file_name", "r") file_out.each_line do |line| do_the_stuf_vith line end On Oct 3, 11:32 pm, Morgan Morgan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> ok so i''m trying to just read out a file line by line and i can''t seem > to figure out how to not get an EOFerror... is there some way to tell > when i get to the end of the file? > > i''m just reading out line by line, splitting it and sticking it in a > database. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@pid = File.new("filename") @pid.each_line do |line| @wid = line.split(" ") puts @wid end am i doing something wrong?.. this just spits out the path to the file instead of anything actually in the file. Dejan Dimic wrote:> file_out = File.new("file_name", "r") > file_out.each_line do |line| > do_the_stuf_vith line > end > > On Oct 3, 11:32�pm, Morgan Morgan <rails-mailing-l...@andreas-s.net>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Raja Venkataraman
2008-Oct-05 08:47 UTC
Re: count number of lines in a file with file.open
Hmm, not sure what you are missing, seems fine to me. irb(main):001:0> f = File.new(''test.txt'') => #<File:test.txt> irb(main):002:0> f.each_line do |line| irb(main):003:1* w = line.split('' '') irb(main):004:1> puts w irb(main):005:1> end First Second Third => #<File:test.txt> My file had First, Second and Third on separate lines. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---