View Single Post
  #12    
Old September 30th, 2012 (11:17 AM).
FL's Avatar
FL FL is online now
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,484
My Ruby test that write and read files:
Code:
def testIO 
  file_name="testIO.txt"
  array=[]
  1000.times do
    array.push(rand(100000))
  end
  p "array",array
  output=""
  for i in 0...array.size
    output+="\n" if(i%10==0 && i!=0)
    output+=sprintf("array[%03d]=%05d ",i,array[i])
  end
  out=[]
  open(file_name,"w"){|f| f.write(output)}
  open(file_name){|f| out=f.readlines(output)}
  array_final=[]
  for m in 0...out.size
    column=out[m].split(" ")
    for n in 0...column.size
      data=column[n]
      data.slice!(0,11)
      array_resposta.push(data)
    end
  end
  p "array_final",array_final
end
Also take a look in Compiler script section (a little complex). An expert can even manage to left the comments untouched.
__________________