Zubair Ansari wrote: > Hi i want to read data in the text file like. > > > username=abcd > password=1234 > > i write code through the counter and i want write code without counter. Building a Hash of your input data is one way to make it convenient to access: opts = {} File.open("test.txt") do |f| f.each_line do |line| opts[$1] = $2 if line =~ /^(.*)=(.*)$/ end end puts opts["username"] puts opts["password"] A lot of Rubyists use a YAML input file instead, which would have the form username: abcd password: "1234" (note the quotes needed to make it parse as a string rather than a number). Then it just becomes: require 'yaml' opts = YAML.load_file("test.yaml") -- Posted via http://www.ruby-forum.com/.