Hi,

Is there a somewhat more elegant and efficient way to do multiple
assignment of pattern match results (than that shown below) that is still a
fairly simple one-liner (i.e. without resorting to auxiliary $n assignments
or to defining a wrapper function)?

# irb.rb
irb(main):001:0> x="aabbbccccdddeeeefffabcdeabcdeabcde"
"aabbbccccdddeeeefffabcdeabcdeabcde"
irb(main):002:0> (t, u, v) = x.scan(/(a+)[^ace]*(c+)[^e]*(e+)/)[0]
["aa", "cccc", "eeee"]

The only problem I have with this example is that scan is going through the
work of producing an array of arrays, even though I only want the first
match:

irb(main):003:0> (t, u, v) = x.scan(/(a+)[^ace]*(c+)[^e]*(e+)/)
[["aa", "cccc", "eeee"], ["a", "c", "e"], ["a", "c", "e"], ["a", "c", "e"]]

Since the cases where I have used analogous Perl idioms in the past tend to
be found in inner loops or in special cases, involve file-length strings,
I'd like to avoid the extra overhead of scan.

And if there is such a technique, I'd also like to be able to us it in an
if condition.

Conrad Schneiker
(This note is unofficial and subject to improvement without notice.)