Urban Hafner <the-master-of-bass / web.de> wrote:
>>to delete char at pos i from string s:
>>s[i] = ""
>>
>>Hope that helps
>>
>Yes, this was it! Thanks for the fast help
>
>Urban

It helped but there are several other problems:
1. If I run the program, I want to get only those Files that are valid
   Ruby code, but there are some files that contain nothing. What did
   I forget?

2. It's annoying to see all the error messages of the interpreter when
   trying to run the created files. I know that I can use `ruby #{child}`
   instead of system("ruby","#{child}"), but does the first return any
   value to determine if the run was successful?

3. The "parent" has to wait until his "child" has finnished. Multithreading
   would be nice, but does it work with an external command (or does it work
   to call the program with the same interpreter instead of starting another
   one?)

As you might see, I'm just beginning to learn ruby

Urban

---

1.upto(20) do
  get = File.new($0,"r")
  child = "#{Time.now.to_f}.rb"
  put = File.new(child,"w")
  lines = get.readlines
  1.upto(Kernel.rand(lines.length)) do
    changeline = Kernel.rand(lines.length-1)
    string = lines[changeline]
    changechar = Kernel.rand(string.length-1)
    if Kernel.rand(128) == 128 then string[changechar] = ""
    else
      chars = Kernel.rand(127).chr
      2.upto(Kernel.rand(5)) do
	chars = chars + Kernel.rand(127).chr
      end
      string[changechar] = chars
    end
    lines[changeline] = string
  end
  lines.each {|item| put.puts(item)}
  put.close
  if system("ruby","#{child}") == false
      File.delete("#{child}")
  end
end