KingMaker KingMaker wrote:
> Text file:
> firstName=abcd
> lastName=xyz
> legalName=test
> vendorRepWorkPhone=121212
> email=abcd / test.com
> confirmEmail=abcd / test.com
> 
> First i read the file and get all values in the data variable.
> 
> 
> contents = File.read("c:/test/Flow1.txt")
> data = contents.map do |line|
>          line.chomp.split("=")[1]
>        end
> 
> 
> 
> than put values in the variable like.
> @FirstName=
> @LastName=
> @LegalName=
> @VendorRepWorkPhone=
> @Email=data
> @ConFirmEmail=
> 
> 
> 
> i use array for copy the values like
> data[0] for first line
> data[1] for second line
> 
> but it is not good if i have 100 value than i write this for 100 times
> in the feature requirement is changed and add some field that time.
> problem arise so plz help me..
> what is the best solution of this....

And what about storing that data in a hash, e.g:

data = Hash.new
File.readlines("c:/test/Flow1.txt").each do |line|
  var,val = line.chomp.split("=")
  data[var] = val
end

puts data['lastName']
puts data['vendorRepWorkPhone']

-- 
Posted via http://www.ruby-forum.com/.