From: "Ara.T.Howard" Date: 2005-08-04T09:25:15+09:00 Subject: Re: regex question On Thu, 4 Aug 2005, Joe Van Dyk wrote: > I have a file that contains the following contents: > > sw_corner = 1000,-1000 > ne_corner = -1000,1000 > > I want to read that file and figure out what the sw_corner and > ne_corner values are. Here's my following attempt, but it looks ugly. > How can I improve it? > > sw_corner = map_data.scan(/sw_corner = ([-\d]+),\s*([-\d]+)/)[0] > ne_corner = map_data.scan(/ne_corner = ([-\d]+),\s*([-\d]+)/)[0] > > Thanks, > Joe (untested) h = {} map_data.each do |line| key, value = line.split %r/=/ h[k.strip] = value.split(%r/,/).map{|n| Integer n} end p h['sw_corner'] p h['nw_corner'] hth. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================