summaryrefslogtreecommitdiff
path: root/sample/occur.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/occur.rb')
-rw-r--r--sample/occur.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/sample/occur.rb b/sample/occur.rb
index 2141fad..f489bee 100644
--- a/sample/occur.rb
+++ b/sample/occur.rb
@@ -1,12 +1,12 @@
# word occurrence listing
# usege: ruby occur.rb file..
-freq = {}
+freq = Hash.new(0)
while gets()
for word in $_.split(/\W+/)
- freq[word] +=1
+ freq[word] += 1
end
end
-for word in freq.keys.sort
- printf("%s -- %d\n", word, freq[word])
+for word in freq.keys.sort!
+ print word, " -- ", freq[word], "\n"
end