analyzer.rb cannot run.

G

Genocide Law

Hi, I'm kinda new to this programmin thing and I'm currently using
windows vista and it seems whenever I run this file:

line = File.readlines("text.txt")
lines_count = lines.size
text = lines.join
puts "#{line_count} lines"

It will show :
ruby C:/Users/administrator/analyzer.rb
*** WARNING *** Windows users should check the "Run process in terminal"
check box in the Debugger Preferences
to see STDOUT and STDERR output in real time.

C:/Users/administrator/analyzer.rb:2: undefined local variable or method
`lines' for main:Object (NameError)

and as you can see, there's an error in the code but I can't seem to
find out what. I have attached the text maybe someone can run it and
tell me what's wrong?

Thanks,

Gen

Attachments:
http://www.ruby-forum.com/attachment/3248/text.txt
 
B

Brian Candler

Genocide said:
Hi, I'm kinda new to this programmin thing and I'm currently using
windows vista and it seems whenever I run this file:

line = File.readlines("text.txt")
lines_count = lines.size
text = lines.join
puts "#{line_count} lines"

It will show :

*** WARNING *** Windows users should check the "Run process in terminal"
check box in the Debugger Preferences
to see STDOUT and STDERR output in real time.

C:/Users/administrator/analyzer.rb:2: undefined local variable or method
`lines' for main:Object (NameError)

and as you can see, there's an error in the code but I can't seem to
find out what. I have attached the text maybe someone can run it and
tell me what's wrong?

The error message does tell you exactly the problem: it's on line 2 of
analyzer.rb, and the problem is that you referred to something called
"lines" but no such thing exists. That is, there is no local variable or
method called "lines"

On line 1 you created a local variable called "line", not "lines" :)

HTH,

Brian.
 
G

Genocide Law

Ha ha, okay, I realized now. I copied the codes wrong too. Anyhow, I got
it done awhile ago. Thankx yeah! :)

P.S. what does HTH means.... -.-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top