rubyのハッシュを使ったプログラミングについてです。
count=Hash.new(0)
File.open(ARGV[0]) do |f| f.each_line do |line| words=line.split words.each do |word| count[word]+=1 end end end
count.sort{|a,b| a[1]<=>b[1] }.each do |key,value| print "#{key}: #{value}\n" end
と入力し、a.rb text.txtと実行したところ、
Traceback (most recent call last):
2: from C:/ruby/a.rb:3:in `<main>' 1: from C:/ruby/a.rb:3:in `open'
C:/ruby/a.rb:3:in `initialize': No such file or directory @ rb_sysopen - text.txt (Errno::ENOENT)
が出てきました。
どなたか正しい修正方法を教えてください!
text.txtには、
"Hello, Myname is Bob. "
とテキストエディタに入力したものを保存してあります。
a.rbとtext.txtは同じファイル内に存在しています。
回答1件
あなたの回答
tips
プレビュー