From: Gavin Sinclair Date: 2004-02-07T15:20:51+09:00 Subject: Re: prepend file line number to array On Saturday, February 7, 2004, 1:51:56 AM, Joseph wrote: > [...] > what i would like to end up with is : > 1 01/02/2004 bought 100 widgets 19.95 company_1 > 2 01/02/2004 sold 5 widgets 22.95 company_2 > 3 01/02/2004 bought 50 widgets 19.95 company_1 > is there an array method that i can use on each element to prepend the line > number after reading the file into an array using IO.readlines? Sure there is! require 'extensions/all' # extensions.rubyforge.org lines = lines.map_with_index { |line, i| "#{i+1} #{line}" } Although this may be more efficient: require 'extensions/all' File.open(path) do |f| lines = f.map_with_index { |line, i| "#{i+1} #{line}" } end Cheers, Gavin