From: Brian Candler Date: 2005-07-19T17:48:34+09:00 Subject: Re: Reading total lines of file then displaying in reverse? On Mon, Jul 18, 2005 at 09:06:26PM +0900, Tristan Knowles wrote: > For my case, it now looks like this: > > lines = IO.readlines("my.log").reverse.each_with_index > do |line, index| > > > I'm trying to use .length somewhere now to count the > number of lines. lines.size will give you the number of lines. Are you trying to do something like this? lines = File.readlines("my.log") lines.reverse.each_with_index do |line, index| index = lines.size - index printf "%5d %s", index, line end Or: c = lines.size lines.reverse_each do |line| printf "%5d %s", c, line c -= 1 end Or the fancy way, if you want to iterate using each_with_index but not create an intermediate reversed copy of the array: require 'enumerator' lines.to_enum(:reverse_each).each_with_index do |line, index| index = lines.size - index printf "%5d %s", index, line end Regards, Brian.