From: matz@... (Yukihiro Matsumoto) Date: 2002-09-20T10:02:46+09:00 Subject: Re: Thoughts on improving usage of Regexp#match Hi, In message "Thoughts on improving usage of Regexp#match" on 02/09/20, "Hal E. Fulton" writes: |I was looking at a piece of code like this: | | sub1 = "" | if str =~ regex | sub1 = $1 | end | |and I thought three things: | 1. I've never liked the $1 -- I usually avoid | Perlish variables, even the common ones. | 2. I don't like the if. | 3. I don't like having to assign sub1 twice. | |So I tried writing: | | sub1 = regex.match(str)[1] || "" How about sub1 = (regex.match(str)[1] rescue "") if you're using 1.7.x? matz.