diff options
Diffstat (limited to 'jni/ruby/sample/freq.rb')
-rw-r--r-- | jni/ruby/sample/freq.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/jni/ruby/sample/freq.rb b/jni/ruby/sample/freq.rb new file mode 100644 index 0000000..1b2194c --- /dev/null +++ b/jni/ruby/sample/freq.rb @@ -0,0 +1,12 @@ +# word occurrence listing +# usage: ruby freq.rb file.. +freq = Hash.new(0) +while line = gets() + line.scan(/\w+/) do |word| + freq[word] += 1 + end +end + +for word in freq.keys.sort! + print word, " -- ", freq[word], "\n" +end |