sample/occur2.rb


DEFINITIONS

This source file includes following functions.


   1  # word occurrence listing
   2  # usege: ruby occur2.rb file..
   3  freq = {}
   4  while gets()
   5    for word in $_.split(/\W+/)
   6      begin
   7        freq[word] = freq[word] + 1
   8      rescue NameError
   9        freq[word] = 1
  10      end
  11    end
  12  end
  13  
  14  for word in freq.keys.sort
  15    printf("%s -- %d\n", word, freq[word])
  16  end