# How to sove the loaderror?

**URL:** <https://www.ruby-forum.com/t/how-to-sove-the-loaderror/193303>\
**Category:** Ruby\
**Created:** [August 15, 2010, 9:13am UTC](https://www.ruby-forum.com/t/how-to-sove-the-loaderror/193303 "2010-08-15T09:13:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [August 15, 2010, 9:13am UTC](https://www.ruby-forum.com/t/how-to-sove-the-loaderror/193303/1 "2010-08-15T09:13:22Z")

</div>

please run the following program in irb,you can get  
1.in irb,you can see  
wrong,/tmp/AACC  
=\> [#\<Thread:0xb76f86c0 dead\>, #\<Thread:0xb76f865c dead\>,  
#\<Thread:0xb76f7b6c dead\>]  
2.there are two files in /tmp  
YHOO AACC  
it is strange for me to save the code into /tmp/test.rb,and  
pt@pt-laptop:~$ ruby /tmp/test.rb  
ruby: No such file or directory – /tmp/test.rb (LoadError)  
please do it ,you will get what i say  
the code is:

require ‘rubygems’  
require ‘net/http’  
threads = []  
str=%w([http://table.finance.yahoo.com/table.csv?s=ALP/N](http://table.finance.yahoo.com/table.csv?s=ALP/N)  
[http://table.finance.yahoo.com/table.csv?s=YHOO](http://table.finance.yahoo.com/table.csv?s=YHOO)  
[http://table.finance.yahoo.com/table.csv?s=AACC](http://table.finance.yahoo.com/table.csv?s=AACC))  
for page\_to\_fetch in str  
threads\<\<Thread.new(page\_to\_fetch) do |url|  
@@myfile=“/tmp/”+url.split(“=”)[1].to\_s  
open(@@myfile,“w”) do |wfile|  
info = net::HTTP.get\_response(URI.parse(url)).body  
wfile.puts info  
end  
end  
end  
threads.each {|thr|  
begin  
thr.join  
rescue Errno::ENOENT=\>e  
puts “wrong,#{@@myfile}”  
end  
}

any advices appreciated.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [August 15, 2010, 9:16am UTC](https://www.ruby-forum.com/t/how-to-sove-the-loaderror/193303/2 "2010-08-15T09:16:46Z")

</div>

sorry , it is  
wrong,/tmp/ALP/N  
not  
wrong,/tmp/AACC

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [August 16, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/how-to-sove-the-loaderror/193303/3 "2010-08-16T16:27:27Z")

</div>

> any advices appreciated.

(1) Don’t use class variables (@@myfile): the value will be shared  
between all three threads, and they will stomp on each other. A local  
variable (myfile) is what you want here.

(2) Do your error handling within the thread code, so you don’t need to  
mess with @@myfile to get sensible error reports outside.

Or simply set:

Thread.abort\_on\_exception = true

at the top of your file. This will let you see the next problem:

(3) change net::HTTP to Net::HTTP

This creates /tmp/ALP/n with a 404 error in it. This seems reasonable to  
me, since if I go to  
[http://table.finance.yahoo.com/table.csv?s=ALP/N](http://table.finance.yahoo.com/table.csv?s=ALP/N)  
in a normal web browser, I also get a 404.

So the next thing you need to do is to work out what URLs you actually  
want to download. The command-line tool “curl” is helpful for this, and  
of course, reading the documentation for the API you’re trying to use.
