From: Paul Lutus Date: 2006-12-10T16:45:04+09:00 Subject: Re: format problem chen li wrote: > Hi all, > > I have a 1D array containing 96 elements. I change it > into a 2D array then print it out: each line/row is an > element with whatever columns I want. The problem is > that if the column number is < 10 I can print out > the format that I want. If the column number is >=10 I > still can print the results but the format is changed. > Also I use object#inspect method to check the data > structure: both of them are an 2D array. If the 1D > array is defined as _1D_array=1..96 then change it to > a 2D array no such problem happens. Any comments? Just one. What are the data, and what result do you want? Show examples of the data that originate in your one dimensional, 96 element array, and show the desired output formatting. Here is an example of what you might want, but this can only be a guess under the circumstances: ------------------------------------- #!/usr/bin/ruby -w array = [] 1.upto(96) { array << rand(256) } max_cols = 10 col = 0 array.each do |item| printf("%4d",item) puts if (col += 1) % max_cols == 0 end puts ------------------------------------- Example output: 88 227 250 145 115 255 93 4 91 5 138 120 26 89 148 225 29 95 71 232 99 166 99 250 23 2 205 147 176 221 228 33 156 97 74 241 7 252 236 85 120 150 46 227 175 23 250 186 151 154 9 245 239 164 242 6 89 180 86 239 27 141 161 251 38 7 190 195 9 106 127 220 112 18 86 247 82 82 122 101 109 250 70 189 224 181 87 116 238 58 124 118 99 18 188 53 -- Paul Lutus http://www.arachnoid.com