summaryrefslogtreecommitdiff
path: root/sample/freq.rb
blob: d951591735231149d7c8e7aef651a4924b3d7c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
# word occurrence listing
# usege: ruby freq.rb file..
freq = {}
while gets
  while sub!(/\w+/, '')
    word = $&
    freq[word] +=1
  end
end

for word in freq.keys.sort
  printf("%s -- %d\n", word, freq[word])
end