rubyで数を数えるプログラムのエラーを解消する方法を教えてください。
プログラムのコードとエラー文を下記に示します。どうすればエラーが解消されるか教えてください。また、csvファイルを使用しているのでそのファイルも下記に示します。よろしくお願いします。
以下のようなrubyのプログラムを書いています。
require 'csv'
hash = Hash.new
File.foreach('sample.csv') do |row|
col = row.chomp.split(",")
if col.length > 4
for i in 3..col.length-1
txt += col[i] + ","
end
end
if hash{:col[2]} == nil
hash{:col[2]} = 1
else
hash{:col[2]} += 1
end
end
puts hash.keys
エラーメッセージ
prog$ ruby freq.rb
freq.rb:12: syntax error, unexpected '=', expecting kEND
hash{:col[2]} = 1
^
freq.rb:14: syntax error, unexpected tOP_ASGN, expecting kEND
hash{:col[2]} += 1
^
prog$
CSVファイル
6,2,4,"<p>One option would be to clone your startup drive to an external disk using something like SuperDuper! or Carbon Copy Cloner. Then you can use System Preferences->Startup Disk to select that external drive as the boot drive. </p>
<p>Once you've rebooted and are running the system off the external drive you can use Disk Utility to run the repair. After you're done, re-select the internal drive as the Startup Disk and reboot.</p>"
(省略)
27,2,12,"<p>They aren't really ""in memory,"" more like cached to disk if and when necessary. Many apps don't even use the multitasking or aren't setup for it. When you switch it does actually close the app.</p>
<p>Being in the task bar doesn't guarantee that it's actually in memory, actively running, or both. The OS manages that. </p>"