in reply to Re: Regex capture consumed by non-capturing match
in thread Regex capture consumed by non-capturing match

I always prefer the form:

my ($foo, $bar) = ($test =~ /(capt-pat-1)...(capt-pat-2)/);

Doesn't get clobbered and is quite readable I think.

-David.

Replies are listed 'Best First'.
Re^3: Regex capture consumed by non-capturing match
by ribasushi (Pilgrim) on Jul 20, 2007 at 15:55 UTC
    Yes, except that it is quite hard to write an if that checks if the match succeeded at all. I omitted this in the example, but in the real code this was the case:
    if ($string =~ /re/) { my ($a, $b, $c) = trim_func ($1, $2, $3); }

      Not so.

      if (my @matches = $string =~ /re/) { my ($a, $b, $c) = trim_func(@matches); }