From: Tom Reilly Date: 2007-09-19T06:22:43+09:00 Subject: Re: removing newline from eachline in file Try changing the code to: file_in = File.new("whatever") file_in.each do |x| url = x.chomp + ".net" gud luck Chuck Dawit wrote: > I'm reading a file line by line and trying to remove the newline at the > end of each line so that I can rebuild the url with the "www" and the > ".net" at the beginning and end. Does anyone know how I can remove the > newline char at the end of each line? Also if the url doesn't work/exist > I don't want the script to crash I want to keep moving through the file > its reading. > > begin > while (line = f.readline) > line = line =~ /(.*?)\n/ > url = "www." + line + ".net" > > open(url) { |page| page_content = page.read() > puts "link exists" > } > end > rescue > puts "link does not exist" > > rescue EOFError > f.close > end >