[Bug #2533] sample/occur2.rb is old-fashioned

Bug #2533: sample/occur2.rb is old-fashioned
http://redmine.ruby-lang.org/issues/show/2533

e$B5/I<<Te(B: Yuki S.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Yukihiro M., Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2009-12-24 trunk 26168) [i386-darwin9.8.0]

Kernel#splite$B$,L5$/$J$C$?$3$H$Ge(Bsample/occur2.rbe$B$,F0$+$J$/$J$C$F$$$?$N$Ge(Br26180e$B$G=$@5$7$^$7$?!#e(B

e$B$=$l$K$7$F$be(Bsample/occur2.rbe$B$O!“:#$+$i8+$k$H$”$^$jNI$/$J$$$h$&$K;W$($^$9!#e(B
e$B0EL[$NJQ?t$r;H$&$“$?$j$,$”$^$j8=Bee(BRubye$BE*$G$J$/!"L50UL#$Ke(BNil#+(Integer)e$B$Ne(BNameErrore$B$G%-!<$NIT:$r%U%)%m!<$7$F$$$k$N$,650i>e9%$^$7$/$J$$$H;W$$$^$9!#e(B
e$BNc30$r;H$C$F$
$k$H$+!“2?$i$+$N0U?^$,$”$C$?$s$G$7$g$&$+!#e(B

e$B8=Be8l$H$7$F$O<!$N$h$&$K$J$k$N$,<+A3$G$O$J$$$+$H;W$$$^$9$,!"$$$+$,$G$7$g$&$+!#$b$7NI$1$l$P:9$7BX$($?$$$H;W$$$^$9!#e(B

diff --git a/sample/occur2.rb b/sample/occur2.rb
index 22cf520…ca87d0d 100644
— a/sample/occur2.rb
+++ b/sample/occur2.rb
@@ -1,13 +1,10 @@

word occurrence listing

usege: ruby occur2.rb file…

freq = {}
-while gets()

  • for word in $_.split(/\W+/)
  • begin
  •  freq[word] += 1
    
  • rescue NameError
  •  freq[word] = 1
    
  • end
    +ARGF.each_line do |line|
  • for word in line.split(/\W+/)
  • freq[word] ||= 0
  • freq[word] += 1
    end
    end

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:39927] [Bug #2533] sample/occur2.rb is
old-fashioned”
on Sun, 27 Dec 2009 09:25:56 +0900, Yuki S.
[email protected] writes:

|Kernel#splite$B$,L5$/$J$C$?$3$H$Ge(Bsample/occur2.rbe$B$,F0$+$J$/$J$C$F$$$?$N$Ge(Br26180e$B$G=$@5$7$^$7$?!#e(B
|
|e$B$=$l$K$7$F$be(Bsample/occur2.rbe$B$O!“:#$+$i8+$k$H$”$^$jNI$/$J$$$h$&$K;W$($^$9!#e(B
|e$B0EL[$NJQ?t$r;H$&$“$?$j$,$”$^$j8=Bee(BRubye$BE*$G$J$/!“L50UL#$Ke(BNil#+(Integer)e$B$Ne(BNameErrore$B$G%-!<$NIT:$r%U%)%m!<$7$F$$$k$N$,650i>e9%$^$7$/$J$$$H;W$$$^$9!#e(B
|e$BNc30$r;H$C$F$
$k$H$+!“2?$i$+$N0U?^$,$”$C$?$s$G$7$g$&$+!#e(B
|
|e$B8=Be8l$H$7$F$O<!$N$h$&$K$J$k$N$,<+A3$G$O$J$$$+$H;W$$$^$9$,!”$$$+$,$G$7$g$&$+!#$b$7NI$1$l$P:9$7BX$($?$$$H;W$$$^$9!#e(B

e$B$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

e$B%A%1%C%He(B #2533 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

This issue was solved with changeset r26188.
Yuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


http://redmine.ruby-lang.org/issues/show/2533