From: "Jesús Gabriel y Galán" Date: 2010-10-27T21:01:24+09:00 Subject: Re: Extraction of single subarrays from multidimensional array On Wed, Oct 27, 2010 at 1:10 PM, Maurizio Cirilli wrote: > Sorry for my bad explanation, in my case I actually know how many > columns are in md-array > i.e how many sub-arrays are to be extracted because I read them as > backtraslated aminocids > from a gene database but this number can change from case to case. So > to make my code of > general use I have to take in consideration this "variable" otherways > I have to change by hand > this number every time I run the program. In the example I provided > this number is 3 but this > number of subarrays can vary. In this respect I wrote "unknown" > dimension. > Sorry again for misunderstanding. The question is: what do you do with those subarrays? What's common in both cases? When you take a look at that answer you can come up with a way of making a generalized algorithm that can work for different sizes, and I bet that you don't need to generate a local variable for each subarray. For example, say that you have to take each subarray, join the strings together comma separated and pass it to a method for further processing: ss = [ .... your array of arrays ...] ss.each {|subarray| process_subarray(subarray.join(",")) } See? You don't need to know there were 2, 3 or 20 subarrays, or even the length of each subarray. So, take a look at the requirement from a higher perspective and you will get to a generalized algorithm. Jesus.