2010/8/27 Pen Ttt <myocean135 / yahoo.cn>:
>
> =A0 =A0there are three =A0program fragments,all of them =A0have same prob=
lems,
> =A0 =A0all =A0of them =A0can run ,but when i downloaded =A030% data,an er=
ror
> ocurr
> =A0 =A0undefined local variable or method `web' for Data:Class (NameError=
)

You need to look into class methods of class Data.  Somewhere there
you will find usage of "web" which is undefined.  Unfortunately you
did not post that class so we cannot tell you where your error is.

> =A0 =A0cthreaddown =A0is an =A0array =A0which contains many web.
> =A0 =A0would you kind to tell =A0me how to fix =A0it?
> =A0 =A0p1
> =A0 =A0 [code]
> =A0 =A0 for page_to_fetch in cthreaddown
> =A0 =A0 threads<<Thread.new(page_to_fetch) do |web|
> =A0 =A0 =A0 =A0 datafile=3D"/home/pt/stock/"
> =A0 =A0 =A0 =A0 open(datafile,'a+'){|refile|
> =A0 =A0 =A0 =A0 open(web){|webfile|
> =A0 =A0 =A0 =A0 =A0 =A0 =A0refile.puts =A0webfile.read

You should use #write with #read and not #puts, because #puts does not
write out arguments unmodified.  Also note that if webfile is large
this approach will break.  You should better use blocked reading.

buffer =3D ""
while webfile.read(1024, buffer)
  refile.write buffer
end

> =A0 =A0 =A0 =A0 =A0 =A0 =A0puts =A0"#{web} =A0is over"
> =A0 =A0 =A0 =A0 }}
> =A0 =A0 =A0 =A0end
> =A0 =A0 =A0end
> =A0 =A0 threads.each {|thr|
> =A0 =A0 =A0 =A0begin
> =A0 =A0 =A0 =A0 thr.join
> =A0 =A0 =A0 =A0 rescue Timeout::Error =3D> e
> =A0 =A0 =A0 =A0 =A0 puts =A0 =A0"#{web} =A0failed"
> =A0 =A0 =A0 =A0 rescue NameError =3D> e
> =A0 =A0 =A0 =A0 =A0 puts =A0 =A0"#{web} =A0failed"
> =A0 =A0 =A0 =A0 rescue =3D> e
> =A0 =A0 =A0 =A0 =A0 puts =A0 =A0"#{web} =A0failed"
> =A0 =A0 =A0 =A0end
> =A0 =A0 =A0 }
> =A0 =A0 =A0[/code]

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/