Hi --

On Thu, 20 Jul 2006, Ricardo Furgeson wrote:

> William James wrote:
>> Ricardo Furgeson wrote:
>>>
>>> "Hello" = "hi miguel"
>>> the table, and wheather to use a hash or arrays.  Can anyone help me
>>> out?
>>
>> table = {}
>> IO.foreach('Data') { |line|
>>   if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x
>>     table[ $1 ] = $2
>>   end
>> }
>>
>> puts table[ "wrong" ]
>
> Thanks for the help William,
>
> I tried the code you wrote, but I got a nil as a result...I modified the
> code as follows:
>
> table = {}
> IO.foreach('Localizable.strings'){ |line|
>  if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "\s*/
>    table[ $1 ] = $2
>  end
> }
>
> am I missing something?

The /x modifier on the end of William's regex means that literal
whitespace is ignored.  (I'm a big non-fan of /x -- I find it hard to
read regular expressions with a lot of insignificant whitespace mixed
in --  but it has a following :-)  Without it, the regex engine will
look for actual spaces around the various quotation marks.


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black     => RUBY FOR RAILS (reviewed on
                                     Slashdot, 7/12/2006!)
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
dblack / wobblini.net              => me