From: Robert Klemme Date: 2011-08-16T00:06:58+09:00 Subject: Re: Unwanted scan() method behavior On Mon, Aug 15, 2011 at 12:48 AM, Panagiotis Atmatzidis wrote: > Hello, > > On 14 Áõã 2011, at 10:22 ì.ì., Gunther Diemant wrote: > >> I would say, you should only call >> x.readlog >> and not >> puts x.readlog >> >> You call put in the method which gives you the desired output. The 'raw' >> output is the return value of the readlog method, which you don't want to be >> printed. > > I had the feeling that it was something that obvious that I'm missing but I focused so much on the function that I missed it! A few more remarks: since those files can be large a better choice is usually to use File.foreach. You can also shorten your regexp a bit by using non capturing groups with repetition markers. Example (untested): File.foreach @logfile do |line| if /^(\d{4}(?:-\d\d){2}).*?(\d{2}(?::\d{2}){2},\d{3}).*?(Ban).*?(\d{1,3}(?:\.\d{1,3}){3})/ =~ line puts "id: #$2 | date: #$1 | IP: #$3" end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/