The case of the missing data
-
Not sure if anyone can find my error just in the code snippet below. The first set of
putsID's the start, and dumps the data. The second set ofputs, shows the results, and the missing "0.0". I have traced the data and it is OK up to here:
@block_z = @insert_names[0] @insert_names = @insert_names - [@insert_names[0]]
In that step, "0.0" vanishes. Any ideas?The portion of my code:
if @line == @insert_names[0
puts "start"
puts @insert_names
@block_name = @insert_names[0]
@insert_names = @insert_names - [@insert_names[0]]
@block_x = @insert_names[0]
@insert_names = @insert_names - [@insert_names[0]]
@block_y = @insert_names[0]
@insert_names = @insert_names - [@insert_names[0]]
@block_z = @insert_names[0]
@insert_names = @insert_names - [@insert_names[0]]
puts "end"
puts @insert_names
end]
and the results of theputs:
%(#0000FF)[start
GROUP_1
-4.944653
-6.740773
0.0
GROUP_2
8.629024
-6.771204
0.0
end
GROUP_1
-4.944653
-6.740773
0.0
start
GROUP_2
8.629024
-6.771204
end
GROUP_2
8.629024
-6.771204
nil] -
not sure about the data - but is this line removing the first item of the array?
@honoluludesktop said:
@insert_names = @insert_names - [@insert_names[0]]
you can do that with:
@insert_names.shift -
You are really tangling things by reducing the contents of
@insert_namesas you go along - it becomes hard to keep track...
Because you know the order, then why no extract the data 4 items at a time?blocks=[] ### or whatever you want to call this array of 'blocks'... inserts=[]+@insert_names ### == a 'copy' while inserts[0] block=[] block[0]=inserts[0] block[1]=inserts[1] block[2]=inserts[2] block[3]=inserts[3] blocks << block inserts=inserts[4..-1] ### strip out first block recursively... end#while ### now 'blocks' contains arrays for each block followed by its x/y/z ### e.g. [[GROUP_1, -4.944653, -6.740773, 0.0],[GROUP_2, 8.629024, -6.771204, 0.0]...] ### '@insert_names' is unchanged.
-
Thanks fellows, let me give those a try:-)
-
Thanks, they both work:-) Ended up fixing my app in a couple of places. Wounder how I mucked the data:-(
Advertisement