From: "Eustáquio 'TaQ' Rangel" Date: 2007-11-14T01:20:52+09:00 Subject: Re: reading a column formatted data -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. > Depending on the column number, these strings (Fair, Excellent, etc) > must be given a different weight, multiplied by the number of these > strings occurrences in a column and an index is to be calculated. > what is the best approach in ruby? Don't know if it's the best but: weight = {0=>1,1=>2,2=>3} scale = {"Poor"=>1,"Fair"=>2,"Excellent"=>3} File.open("suresh.txt").each do |line| value, (name, *values) = 0, line.split values.each_with_index {|item,index| value += weight[index]*scale[item]} puts "[#{name}] [#{values.join(',')}] [#{value}]" end > suresh Wow! Dr. Suresh from Heroes??? :-) - -- Eust�quio "TaQ" Rangel http://eustaquiorangel.com "Premature optimisation is the root of all evil." Donald Knuth -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFHOc7Xb6UiZnhJiLsRAmDeAJ9gwMYrgsLzf98j3TIQOl09TpsBTgCgq7OI RsFHTwjXRUK2oeTiUVUwbEk= =/Vt2 -----END PGP SIGNATURE-----