there are three  program fragments,all of them  have same problems,
    all  of them  can run ,but when i downloaded  30% data,an error
ocurr
    undefined local variable or method `web' for Data:Class (NameError)
    cthreaddown  is an  array  which contains many web.
    would you kind to tell  me how to fix  it?
    p1
     [code]
     for page_to_fetch in cthreaddown
     threads<<Thread.new(page_to_fetch) do |web|
         datafile="/home/pt/stock/"
         open(datafile,'a+'){|refile|
         open(web){|webfile|
              refile.puts  webfile.read
              puts  "#{web}  is over"
         }}
        end
      end
     threads.each {|thr|
        begin
         thr.join
         rescue Timeout::Error => e
           puts    "#{web}  failed"
         rescue NameError => e
           puts    "#{web}  failed"
         rescue => e
           puts    "#{web}  failed"
        end
       }
      [/code]
     p2
     [code]
     for page_to_fetch in cthreaddown
     threads<<Thread.new(page_to_fetch) do |web|
         datafile="/home/pt/stock/"
         open(datafile,'a+'){|refile|
         begin
        open(web){|webfile|
              refile.puts  webfile.read
              puts "#{web}  is over"
         }}
        rescue NameError => e
           puts    "#{web}  failed"
        rescue => e
           puts  "#{web}  wrong"
         end
       end
      end
      threads.each {|thr|  thr.join }
     [/code]

     p3
     [code]
     for page_to_fetch in cthreaddown
     threads<<Thread.new(page_to_fetch) do |web|
         datafile="/home/pt/stock/"
         open(datafile,'a+'){|refile|
         begin
        open(web){|webfile|
              refile.puts  webfile.read
              puts "#{web}  is over"
         }}
        rescue NameError => e
           puts    "#{web}  failed"
        rescue => e
           puts  "#{web}  wrong"
         end
       end
      end
   threads.each {|thr|
        begin
         thr.join
         rescue Timeout::Error => e
           puts    "#{web}  failed"
         rescue NameError => e
           puts    "#{web}  failed"
         rescue => e
           puts    "#{web}  failed"
        end
       }
-- 
Posted via http://www.ruby-forum.com/.