From: Julian Leviston Date: 2009-02-16T19:54:33+09:00 Subject: Re: How to do this complicated logic in ruby Loop the array, changing the values of the hash as you go based on some conditional. It's not complex at all. What are you finding difficult? Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 16/02/2009, at 9:00 PM, Valentino Lun wrote: > Dear all > > I have an array with size around 1000, I want to perform some data > checking and correction in this array. > > For instance, the first record of this array is a hash, as follow > my_array[0] = {"server"=>"AHN", "hosp"=>"AHN", "loc"=>"PC1", > "pspec"=>"ANA", "number"=>"1", "pcat"=>"1"} > > server hosp loc pspec pcat > AHN AHN PC1 ANA 1 > PWH AHN PC1 ANA 1 > NDH AHN PC1 ANA 2 <= This pcat value need update in > array1 > TMH AHN PC1 ANA 2 <= This pcat value need update in > array1 > ....... > ..... > ... > (around 1000 records) > > When keys hosp, loc, pspec has the same values, their pcat must be > identical. So, there is problem in the last two records, the key pcat > should be 1, because the pcat is correct if array["server"] equal to > array["hosp"]. > > I cannot figure out the logic to doing this in ruby (even in other > language). Can someone give me some hints on this? Thanks > > Many thanks > Valentino > -- > Posted via http://www.ruby-forum.com/. >