From: Eirik Meland Date: 2001-12-15T10:30:13+09:00 Subject: [ruby-talk:28571] Re: Dictionary.com speeder upper "Ralph Mason" writes: This would be even more elegant using scan instead of =~, $' and $` (I think of $' and $` as rather perlish) > require "net/http" > > if ARGV.size == 0 > puts "Usage: dictionary term" > exit > end > > a = Net::HTTP.get("www.dictionary.com","/cgi-bin/dict.pl?term=#{ARGV[0]}") > > if ( a=~/No entry found for/ ) > puts "No entry found for '#{ARGV[0]}' - Suggestions:\n\n" > > while $' =~/(\w+)/ > puts $1 > end Instead of the while loop: a.scan( /(\w+)/ ) { |res| puts res } > else > while a =~ // > $' =~ // > a=$' > > puts $`.gsub(/<.*?>/m){ |i| > case i > when "" > "" > when "" > "\n" > when "

" > "" > else > "" > end > } > end Instead of the while loop: a.scan( /(.*?)/m ) { |res| puts res.to_s.gsub( /<.*?>/m ) { |i| i =~ /<\/b>/ ? "\n" : "" #/ just to please my emacs highlighting } } > end -- mvh Eirik Meland