From: Florian Frank Date: 2003-08-22T19:50:15+09:00 Subject: Re: What attracts me to Ruby On 2003-08-21 03:37:20 +0900, Dan Doel wrote: > For example: > > re = /(.)(.)((.).)/ > match = re.match "abcd" > > if match > p match[0] > p match[1] > p match[2] > p match[3] > p match[4] > end I try to minimize the usage of the Perl special variables in Ruby, too. But sometimes they can't be avoided. An idiom I use fairly often is this: case string when /(\d+)/ then puts "Numeric: " + $1 when /([A-Za-z]+)/ then puts "Alphabetic: " + $~[1] end It doesn't seem to be possible to get the return value of the === method in a general way either. A cleaner solution without special variables would require a syntax change for the case expression similar to that: case string as match when /(\d+)/ then puts "Numeric: " + match[1] when /([A-Za-z]+)/ then puts "Alphabetic: " + match[1] end match would be assigned to === string if the keyword "as" is used to allow postprocessing in the when clauses. -- Were it left to me to decide whether we should have government without newspapers or newspapers without government, I should not hesitate for a moment to prefer the latter. But I should mean that every man should receive those papers and be capable of reading them. -- Thomas Jefferson