Foreach.rb

This content was produced by an LLM and could include errors.

This script compares lines from two input files using nested loops. It efficiently searches for and prints every line that is identical (a match) between the two specified text files.

File.foreach('input/file/foreach_b.txt') do |line1|
  File.foreach('input/file/foreach_a.txt') do |line2|
    if line1.eql?(line2)
      puts("MATCHED: #{line1}")
      break
    end
  end
end
MATCHED: 9
MATCHED: 2
MATCHED: 6
#=> nil

Ruby 4.0.3