in reply to Get all captured substrings after a substitution

Polynomial,
With Perl 5.10.x, there is support for named captures. If you can't guarantee perl 5.10.x, then there is Regexp::NamedCaptures by diotalevi but I have no idea how stable it is. I know you said anonymous but doesn't your problem go away if you no longer treat them that way?

Cheers - L~R

  • Comment on Re: Get all captured substrings after a substitution

Replies are listed 'Best First'.
Re^2: Get all captured substrings after a substitution
by Polynomial (Acolyte) on Aug 14, 2009 at 12:48 UTC
    Turns out I actually used m//g, not s///; goodness knows why I thought otherwise. And it does look like the best solution for my situation is indeed to use named captures, since I'm running perl 5.10.0. I just have to make sure to copy %+ into a lexical hash so all the captures remain accessible after I've used another regex. In future cases where I really do want seperate lexicals as opposed to a hash (and hence anonymous as opposed to named captures), I guess I can use @+ and @- with substr or eval, as has been suggested; I'd just want to benchmark each method to see which is fastest. Thank you, kind monks.