From: dblack@... Date: 2003-08-24T20:58:17+09:00 Subject: Re: Why did you switch from Python to Ruby? Hi -- On Sun, 24 Aug 2003, Tristan (kesuari) wrote: > Date: Fri, 22 Aug 2003 19:39:08 -0000 > To: judoscript@yahoogroups.com > Subject: JudoScript is great for hacks! (#1) > Message-ID: > User-Agent: eGroups-EW/0.82 > X-Mailer: Yahoo Groups Message Poster > From: "j2geek" > > ------------wc.ruby--------------------------------------- > > nl = nw = nc = 0 > loop do > data = (STDIN.read(4096) or break) << (STDIN.gets || "") > nc += data.length > nl += data.count("\n") > ((data.strip! || data).tr!("\n", " ") || data).squeeze! > nw += data.count(" ") + 1 > end > puts "#{nl} #{nw} #{nc}" This version of wc doesn't work: $ echo | ruby wc.rb 1 1 1 (Note faulty word count of 1.) Not that I'd expect anyone to cut-and-paste the code for daily use -- there are much nicer ways to do this, as we've seen -- but if you do, you might want to fix it :-) David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav