Dossy graced us by uttering:
> Maybe this is Perl envy, maybe I'm just doing something wrong.
> I'd like to be able to say this:
> 
>   x, y = "foo bar" =~ /(foo) (bar)/
> 
> and x == "foo" and y == "bar"

The main problem I see with this (even as a perl idiom) is that you're
attempting to assign variables without checking the success of the
match.  Without knowing the actual code you'll be using this example
with, it's a valid warning that, if the regex doesn't match the string,
then x would be assigned the result of the match (nil) and y would
retain the value it held before the statement (possibly nil as well).

A more perlish idiom would be:

  if ("foo bar" =~ /(foo) (bar)/) {
    ($x, $y) = ($1, $2);
  }

which translates to:

  if /(foo) (bar)/ =~ "foo bar"
    x, y = $1, $2
  end

or

  if /(foo) (bar)/ =~ "foo bar"
    x, y = $~[1..2]
  end

> Currently, String#=~ returns the character of the first match.
> I have to do this:
> 
>   "foo bar" =~ /(foo) (bar)/
>   junk, x, y = $~.to_a
> or
>   x, y = $1, $2

Since $~ can already be accessed as an array using the [] method (see
above), don't call #to_a to make a needless copy of the array which you
just throw away anyway.

    x, y = $~[1..2]

accomplishes the same as

    x, y = $~.to_a[1..2]

but uses one less method call and one less intermediate variable.

Tim Hammerquist
-- 
We do not joke about eating people in this house!
    -- Buffy, "Buffy the Vampire Slayer"