意外的关键字结束错误,但语法似乎很好 [英] Unexpected keyword_end error, yet syntax seems fine
本文介绍了意外的关键字结束错误,但语法似乎很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个函数应该从逗号分隔值文件中提取名称,并将它们放入一个数组中.
This function is supposed to pull names from a Comma Separated Values file, and place them into an array.
def xprt_csv_to_ary(csv_file)
namecatcher_regex = "/^[\.{1}]([A-Z]+)\.{3}/" # Matches up to char before next name
current_word = 0
names_array = []
while current_word < 5000
if current_word == 0
name = csv_file.readline.match(namecatched_regex)
else
name = csv_file.past_match.match(namecatcher_regex)
end
names_array[current_word] = name
current_word ++
end
return names_array
end
我收到以下错误:
syntax error, unexpected keyword_end
如果有人直接回答我,我会很高兴被提及解决我的问题的现有问题.
I would be as happy to be referred to an existing question that solves my problem as to have someone answer me directly.
推荐答案
您的错误来自行:
current_word ++
Ruby 中没有这样的语法.应该是:
There's no such syntax in Ruby. It should be:
current_word += 1
此外,您错误地创建了正则表达式.应该是:
What's more, you create your regexp incorrectly. It should be:
namecatcher_regex = /^[\.{1}]([A-Z]+)\.{3}/
可能还有一些我没有注意到的其他错误.
There may be some other errors that I didn't notice.
这篇关于意外的关键字结束错误,但语法似乎很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文