diff options
author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-09-08 07:09:52 +0000 |
---|---|---|
committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-09-08 07:09:52 +0000 |
commit | b1f96af92f5b8519c477de3bd8917e5220442f6b (patch) | |
tree | c29d1f6370f4498547c80a69e0440256eeaf39e7 /sample/freq.rb | |
parent | 48acbc5e03622f1eb0423a6c2a3a603f61acfac6 (diff) |
This commit was manufactured by cvs2svn to create tag 'v1_1d-start'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_1d-start@299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/freq.rb')
-rw-r--r-- | sample/freq.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sample/freq.rb b/sample/freq.rb index 16bf1794be..4e0206c114 100644 --- a/sample/freq.rb +++ b/sample/freq.rb @@ -1,13 +1,13 @@ # word occurrence listing # usege: ruby freq.rb file.. -freq = {} +freq = Hash.new(0) while gets while sub!(/\w+/, '') word = $& - freq[word] = freq.fetch(word, 0)+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 |