In article <20020518152610.GJ9684 / panoptic.com>, Dossy wrote:

> No, the Perlish idiom is:
> 
>   ($x, $y) = ("foo bar" =~ /(foo) (bar)/);
> 
> As I said, this is more Perl wantarray() envy.  In perl, the =~
> operator knows if it's being used in the context of expecting a
> scalar vs. an array.  If it's a scalar context, it returns 1 if
> there was a match or 0 if there wasn't.  In an array context,
> it returns $1..$n match expressions as an array.

[...]

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

> Sigh.  ;-)  I guess it'll have to do.  ;-)

But in perl you should check that the array assignment happened e.g.

  if (my ($x, $y) = "foo bar" =~ /(foo) (bar)/) {
     ...
  }

if you want to use $x and $y "safely", and that's not much more concise
than the Ruby.

Mike

-- 
mike / stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike / exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA