P
Pen Ttt
probem1:
the following program can only run in irb console,it can't run with
command :
ruby /home/test.rb,why?
require 'rubygems'
require 'net/http'
threads = []
open("/home/pt/test/data","a+") do |wfile|
str=%w(http://table.finance.yahoo.com/table.csv?s=IBM
http://table.finance.yahoo.com/table.csv?s=YHOO
http://table.finance.yahoo.com/table.csv?s=AACC)
for page_to_fetch in str
Thread.new(page_to_fetch) do |url|
info = Net::HTTP.get_response(URI.parse(url)).body
puts info
end
end
threads.each {|thr| thr.join}
end
problem2:
i want to write output into my file,just change "puts info" into
"wfile.puts info",it can not run.
require 'rubygems'
require 'net/http'
threads = []
open("/home/pt/test/data","a+") do |wfile|
str=%w(http://table.finance.yahoo.com/table.csv?s=IBM
http://table.finance.yahoo.com/table.csv?s=YHOO
http://table.finance.yahoo.com/table.csv?s=AACC)
for page_to_fetch in str
Thread.new(page_to_fetch) do |url|
info = Net::HTTP.get_response(URI.parse(url)).body
wfile.puts info
end
end
threads.each {|thr| thr.join}
end
the following program can only run in irb console,it can't run with
command :
ruby /home/test.rb,why?
require 'rubygems'
require 'net/http'
threads = []
open("/home/pt/test/data","a+") do |wfile|
str=%w(http://table.finance.yahoo.com/table.csv?s=IBM
http://table.finance.yahoo.com/table.csv?s=YHOO
http://table.finance.yahoo.com/table.csv?s=AACC)
for page_to_fetch in str
Thread.new(page_to_fetch) do |url|
info = Net::HTTP.get_response(URI.parse(url)).body
puts info
end
end
threads.each {|thr| thr.join}
end
problem2:
i want to write output into my file,just change "puts info" into
"wfile.puts info",it can not run.
require 'rubygems'
require 'net/http'
threads = []
open("/home/pt/test/data","a+") do |wfile|
str=%w(http://table.finance.yahoo.com/table.csv?s=IBM
http://table.finance.yahoo.com/table.csv?s=YHOO
http://table.finance.yahoo.com/table.csv?s=AACC)
for page_to_fetch in str
Thread.new(page_to_fetch) do |url|
info = Net::HTTP.get_response(URI.parse(url)).body
wfile.puts info
end
end
threads.each {|thr| thr.join}
end