summaryrefslogtreecommitdiff
path: root/sample/occur2.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/occur2.rb')
-rw-r--r--sample/occur2.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/sample/occur2.rb b/sample/occur2.rb
new file mode 100644
index 0000000000..6e0513707c
--- /dev/null
+++ b/sample/occur2.rb
@@ -0,0 +1,14 @@
+freq = {}
+while gets()
+ for word in $_.split(/\W+/)
+ protect
+ freq[word] = freq[word] + 1
+ resque
+ freq[word] = 1
+ end
+ end
+end
+
+for word in freq.keys.sort
+ printf("%s -- %d\n", word, freq[word])
+end