From 210367ec889f5910e270d6ea2c7ddb8a8d939e61 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 20 Jan 1999 04:59:39 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r372, which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/occur.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sample/occur.rb') diff --git a/sample/occur.rb b/sample/occur.rb index 2141fade38..f489beee17 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 -- cgit v1.2.3