strange ruby error

J

Junkone

i get strange error test.rb.rb:14: syntax error, unexpected '}'

makes no sense as the only time i use } is to close the each block. pl
help
require 'fastercsv'
#put everything in an array
array = FasterCSV.read("c:\\temp\\two.txt")
seconds=0
lastminute=0
array.each{|row|
minute=row[1].split(":")[1].to_i
puts minute
puts lastminute
if(minute =lastminute) then
puts "same as last minute"
seconds=seconds+1
end if
}
 
S

Su Zhang

i get strange error test.rb.rb:14: syntax error, unexpected '}'

makes no sense as the only time i use } is to close the each block. pl
help
require 'fastercsv'
#put everything in an array
array = FasterCSV.read("c:\\temp\\two.txt")
seconds=0
lastminute=0
array.each{|row|
minute=row[1].split(":")[1].to_i
puts minute
puts lastminute
if(minute =lastminute) then
puts "same as last minute"
seconds=seconds+1
end if
}
You have an extra `if' after the last `end'.

Su
 
J

John Feminella

You have a number of small syntax/logical errors here, I think. First,
the "then" in this line should be removed:
=C2=A0 =C2=A0 if(minute =3Dlastminute) then

as should the "if" at the very end:
=C2=A0 =C2=A0 end if

Also, you probably meant "minute =3D=3D lastminute", not "=3D", which will
assign lastminute to minute (that's probably not what you want).

It should just be:

if minute =3D=3D last_minute
# ...
end

~ jf
--
John Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: http://stackoverflow.com/users/75170/



i get strange error test.rb.rb:14: syntax error, unexpected '}'

makes no sense as the only time i use } is to close the each block. pl
help
require 'fastercsv'
#put everything in an array
array =3D FasterCSV.read("c:\\temp\\two.txt")
seconds=3D0
lastminute=3D0
array.each{|row|
=C2=A0minute=3Drow[1].split(":")[1].to_i
=C2=A0puts minute
=C2=A0puts lastminute
=C2=A0 =C2=A0 if(minute =3Dlastminute) then
=C2=A0 =C2=A0 puts "same as last minute"
=C2=A0 =C2=A0 =C2=A0 seconds=3Dseconds+1
=C2=A0 =C2=A0 end if
=C2=A0}
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top