From: James Ponder Date: 2001-04-21T10:45:38+09:00 Subject: [ruby-talk:13953] regexp Hi, I'm new to ruby and am coming from a perl background - therefore I was hoping to use the perlisms in ruby when it came to regexps. Quite often you have an input line, and you want to pull data out from it using a regexp. In perl I would do the following, naming my fields without ever using $1, $2, etc.: if (($key, $val) = $var =~ /^(.+)=(.+)$/) { # ... } In ruby, the =~ String instance method returns the position of the match (which perl does when in scalar context) rather than an array of matches, so I'm finding it quite difficult to find a way to do the above perl code, which in my mind is very readable and understandable. I thought about doing key, val = var =~ /^(.+)=(.+)$/ && $~[1..-1] if key ... but nobody would be able to read my code (besides I started feeling sick)... so at the moment I just do: if var =~ /^(.+)=(.+)$/ key, val = $1, $2 but that's no where near as nice as perl's one-liner (and I really hate using $1, $2 etc.). Any ideas? Best wishes, James -- James Ponder; www.squish.net