I need to process some text files quickly. I''ve not been able to find the answer in the archive. The Ruby Standard Library site times out. Can someone tell me where to find info on how to: 1. Get a list of filenames in a directory. 2. How to open a file. 3. How to read it a line at a time. -- Thanks in advance for the help, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
1. Dir[''*.txt''].each do |file| puts file end 2. File.open("my_file.txt").each do |line| puts line end On 12/29/05, Larry Kelly <ldk2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to process some text files quickly. I''ve not been able to find the > answer in the archive. The Ruby Standard Library site times out. Can > someone tell me where to find info on how to: > 1. Get a list of filenames in a directory. > 2. How to open a file. > 3. How to read it a line at a time. > > > -- > Thanks in advance for the help, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Wagner Narde wnarde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Great! Thanks, -L On 12/29/05, Wagner Narde <wnarde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 1. > Dir[''*.txt''].each do |file| > puts file > end > > > 2. > File.open("my_file.txt").each do |line| > puts line > end > > On 12/29/05, Larry Kelly <ldk2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I need to process some text files quickly. I''ve not been able to find > the > > answer in the archive. The Ruby Standard Library site times out. Can > > someone tell me where to find info on how to: > > 1. Get a list of filenames in a directory. > > 2. How to open a file. > > 3. How to read it a line at a time. > > > > > > -- > > Thanks in advance for the help, > > -Larry > > "Work, work, work...there is no satisfactory alternative." > > --- E.Taft Benson > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > Wagner Narde > wnarde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
How do I strip the cr/lf from the end of the line? On 12/29/05, Wagner Narde <wnarde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 1. > Dir[''*.txt''].each do |file| > puts file > end > > > 2. > File.open("my_file.txt").each do |line| > puts line > end > > On 12/29/05, Larry Kelly <ldk2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I need to process some text files quickly. I''ve not been able to find > the > > answer in the archive. The Ruby Standard Library site times out. Can > > someone tell me where to find info on how to: > > 1. Get a list of filenames in a directory. > > 2. How to open a file. > > 3. How to read it a line at a time. > > > > > > -- > > Thanks in advance for the help, > > -Larry > > "Work, work, work...there is no satisfactory alternative." > > --- E.Taft Benson > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > Wagner Narde > wnarde-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Larry Kelly wrote:> How do I strip the cr/lf from the end of the line? >use String#chomp, something like "string\n".chomp => "string" -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
Thanks, I knew it was something really simple. But, just couldn''t remember what it was. -Larry On 12/29/05, Dee Zsombor <dee.zsombor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Larry Kelly wrote: > > How do I strip the cr/lf from the end of the line? > > > use String#chomp, something like "string\n".chomp => "string" > > -- > Company - http://primalgrasp.com > Thoughts - http://deezsombor.blogspot.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
All of this stuff could have been answered by looking it up in the pickaxe book...what are we, "ruby-reference-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org"? :p On 12/29/05, Larry Kelly <larry-4CclAJGh8cqlzlObeVyAOA@public.gmane.org> wrote:> > Thanks, I knew it was something really simple. But, just couldn''t > remember what it was. > -Larry > > On 12/29/05, Dee Zsombor < dee.zsombor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Larry Kelly wrote: > > > How do I strip the cr/lf from the end of the line? > > > > > use String#chomp, something like "string\n".chomp => "string" > > > > -- > > Company - http://primalgrasp.com > > Thoughts - http://deezsombor.blogspot.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- seth at subimage interactive http://www.subimage.com/sublog/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails