From: Bil Kleb Date: 2007-11-13T10:11:08+09:00 Subject: Re: comp.lang.fortran challenge James Edward Gray II wrote: > On Nov 12, 2007, at 8:10 AM, Bil Kleb wrote: >> Nice; can it handle the data which has some unequal (u,v) sets? > > Sure can. Try it out. Sure enough. Why didn't you use a case? E.g., require 'open-uri' us, vs = Array.new, Array.new open 'http://home.earthlink.net/~dave_gemini/demo.in' do |ios| ios.each_line do |line| case line when /time\s*:\s*(.*)/ then # output time puts "for time #{$1}" puts when /(U|V)(.*?)\s*=\s*([\d.]+)/ then # capture and echo U & V lines ($1 == "U" ? us : vs) << [ $2, $3.to_f ] puts line when /^\s*$/, ios.eof? then # output UVs and reset U & V arrays next if us.empty? or vs.empty? us.each do |coordinates, u| next unless v = vs.assoc(coordinates) puts "UV%s = %7.3f" % [coordinates, u * v.last] end puts [us, vs].each { |array| array.clear } end end end Later, -- Bil Kleb http://fun3d.larc.nasa.gov