What can I do with this program to improve its performance?
#!/usr/bin/env ruby
require 'open-uri'
print "URL: "
add = gets
puts "Info from #{add}"
begin
open(add) do |f|
puts "Fetching images..."
puts "Fetching links..."
puts "Fetching div tags..."
puts "Fetching headers..."
puts "Fetching forms..."
puts "Processing..."
img = f.read.scan(/<img/).length
puts "\t#{img} images"
f.close
end
open(add) do |f|
links = f.read.scan(/<a/).length
puts "\t#{links} links"
f.close
end
open(add) do |f|
div = f.read.scan(/<div/).length
puts "\t#{div} div tags"
f.close
end
open(add) do |f|
head = f.read.scan(/<h1/).length
puts "\t#{head} 'h1 type' headers"
f.close
end
open(add) do |f|
form = f.read.scan(/<form/).length
puts "\t#{form} forms"
f.close
end
rescue
puts "An error occured, either you entered an invalid URL or your internet connection is messed up!"
end