bigbrother
12/18/2007 9:40:00 PM
On Dec 18, 2:59 pm, Sebastian Hungerecker <sep...@googlemail.com>
wrote:
> bigbrother wrote:
> >> Drew Olson wrote:
> >>> File.open("my_log.txt") do |line|
> >>> user = line.scan(/US=(\w+)/).flatten.first
> >>> user_requests[user] += 1
> >>> end
>
> > Cool, thanks. When I'm trying it though I get
> > Joshua$./test.rb
> > ./test.rb:4: private method `scan' called for #<File:access.log
> > (...)
> > What does that mean?
>
> It means that you're calling scan on line when line is File object which
> doesn't have scan. If you change File.open to File.foreach, line will
> actually be a line of the file (i.e. a string) and the code will work.
>
> HTH,
> Sebastian
> --
> NP: Sentenced - With Bitterness And Joy
> Jabber: sep...@jabber.org
> ICQ: 205544826
I'm dumb or something's not right
jthomas@jthomas-desktop:~/work$ ./test.rb
../test.rb:14: undefined method `>' for nil:NilClass (NoMethodError)
from ./test.rb:20:in `inject'
from ./test.rb:13:in `each'
from ./test.rb:13:in `inject'
from ./test.rb:13
Sorry guys, I'm really new to programming.