From: Gary Wright Date: 2007-04-09T15:59:37+09:00 Subject: Re: Nesting Array loops On Apr 9, 2007, at 2:49 AM, Rubic wrote: > want to check every element of the array and compare it against rest > of the elements of that array for repeat occurences. but for now I did > be happy if I can get to even print the 2 values, hence 'puts #i, > #j' in > the code. > > > f = File.open("iplist.txt") > f1 = File.open("iplist.txt") > f.each { |i| > f1.each { |j| > puts "#{i}, #{j}" > } > } Those aren't arrays, they are files. You can't assume that enumerable objects can be iterated more than once. You can reopen the file with each iteration or you can use File#rewind to 'back up' to the beginning of the file: f = File.open("iplist.txt") f.each { |i| File.open("iplist.txt") { |f1| f1.each { |j| puts "#{i.chomp}, #{j.chomp}" } } } f = File.open("iplist.txt") f1 = File.open("iplist.txt") f.each { |i| f1.each { |j| puts "#{i.chomp}, #{j.chomp}" } f1.rewind }