From: Richard Lionheart Date: 2004-06-27T19:04:27+09:00 Subject: Re: Writing UNIX 'wc' program Hi, I like the following because: 1. It doesn't store the input in an array 2. As a toy program, it's easier to provide the data in-line rather than through $stdin 3. It's quite succinct, IMHO max_len = wd_cnt = 0 DATA.each_line do |line| line.chomp! max_len = line.length > max_len ? line.length : max_len # Note: pattern recognizes contractions (embedded apostrophe) wd_cnt += line.scan(/\w+'?(\w+)?/).size end puts "Max. len. = #{max_len}" puts "Wd. count = #{wd_cnt}" # Yogi'isms __END__ When asked about his philosophy of life, he replied: "When you reach a fork in the road, take it!" When Yogi was told that Dublin, Ireland elected a Jewish mayor, he excalimed: "only in America!" When asked "What time is it?", Yogi inquired: "You mean now?" "No one goes to that restaurant any more: it's too crowded!" HTH, Richard --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.708 / Virus Database: 464 - Release Date: 6/23/2004