SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
FNAME = "KEN_ALL.CSV"
count = []
File.open(FNAME, "r:SJIS:UTF-8") do |f|
while line = f.gets
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=> [[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = []
File.open(FNAME, "r:SJIS:UTF-8") do |f|
while line = f.gets
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = []
body = nil
File.read(FNAME, “r:SJIS:UTF-8"){|f|
body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
FNAME = "KEN_ALL.CSV"
count = []
body = nil
File.read(FNAME, “r:SJIS:UTF-8"){|f|
body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= []
count[Regexp.last_match[0]] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= []
count[Regexp.last_match[0]] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {” ” => 0}
count = Hash.new { 0 }
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count.sort_by{|k, v| v }
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化

Más contenido relacionado

Destacado

TOEICテスト学習コース~ETS公式問題集収録~
TOEICテスト学習コース~ETS公式問題集収録~TOEICテスト学習コース~ETS公式問題集収録~
TOEICテスト学習コース~ETS公式問題集収録~Uchida Human Development
 
デバッガでデバッグしない
デバッガでデバッグしないデバッガでデバッグしない
デバッガでデバッグしないよしだ あつし
 
Next GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースNext GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースよしだ あつし
 
Twitterでネットストーカーをしよう
TwitterでネットストーカーをしようTwitterでネットストーカーをしよう
Twitterでネットストーカーをしようよしだ あつし
 
僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法よしだ あつし
 
私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development についてよしだ あつし
 
よい名前を付けましょう リーダブルなんたらとか
よい名前を付けましょう   リーダブルなんたらとかよい名前を付けましょう   リーダブルなんたらとか
よい名前を付けましょう リーダブルなんたらとかよしだ あつし
 
15分でできるSQLインジェクション
15分でできるSQLインジェクション15分でできるSQLインジェクション
15分でできるSQLインジェクションよしだ あつし
 
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
 GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ  GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ Hiroyuki Tanaka
 

Destacado (15)

TOEICテスト学習コース~ETS公式問題集収録~
TOEICテスト学習コース~ETS公式問題集収録~TOEICテスト学習コース~ETS公式問題集収録~
TOEICテスト学習コース~ETS公式問題集収録~
 
デバッガでデバッグしない
デバッガでデバッグしないデバッガでデバッグしない
デバッガでデバッグしない
 
Next GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースNext GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリース
 
テスト駆動開発入門
テスト駆動開発入門テスト駆動開発入門
テスト駆動開発入門
 
Twitterでネットストーカーをしよう
TwitterでネットストーカーをしようTwitterでネットストーカーをしよう
Twitterでネットストーカーをしよう
 
僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法
 
私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について
 
よい名前を付けましょう リーダブルなんたらとか
よい名前を付けましょう   リーダブルなんたらとかよい名前を付けましょう   リーダブルなんたらとか
よい名前を付けましょう リーダブルなんたらとか
 
Railsの今昔
Railsの今昔Railsの今昔
Railsの今昔
 
Rails3使用雑感
Rails3使用雑感Rails3使用雑感
Rails3使用雑感
 
15分でできるSQLインジェクション
15分でできるSQLインジェクション15分でできるSQLインジェクション
15分でできるSQLインジェクション
 
Dockerプレゼン
DockerプレゼンDockerプレゼン
Dockerプレゼン
 
Gitの使い方あれこれ
Gitの使い方あれこれGitの使い方あれこれ
Gitの使い方あれこれ
 
Vue.js入門
Vue.js入門Vue.js入門
Vue.js入門
 
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
 GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ  GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
 

Último

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 

Último (20)

AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 

Rubyコードの最適化

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. FNAME = "KEN_ALL.CSV" count = [] File.open(FNAME, "r:SJIS:UTF-8") do |f| while line = f.gets next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=> [[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 16.
  • 17. FNAME = "KEN_ALL.CSV" count = [] File.open(FNAME, "r:SJIS:UTF-8") do |f| while line = f.gets next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 18. FNAME = "KEN_ALL.CSV" count = [] body = nil File.read(FNAME, “r:SJIS:UTF-8"){|f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
  • 19. FNAME = "KEN_ALL.CSV" count = [] body = nil File.read(FNAME, “r:SJIS:UTF-8"){|f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 20. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= [] count[Regexp.last_match[0]] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 21. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= [] count[Regexp.last_match[0]] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 22. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 23. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 24. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 25. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 26. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 27. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 28. FNAME = "KEN_ALL.CSV" count = {” ” => 0} count = Hash.new { 0 } body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count.sort_by{|k, v| v }