in reply to Bug or feature? s/// and the g option
In my mind, this is a documentation bug. If you match instead of substitute, you'll get the expected behavior. Also, the substitution does, in fact, substitute exactly what you ask it to.
I'm grateful that this question led me to spend a couple hours re-reading perlre et al but I never did find anything that explained this behavior. This could easily be an oversight on my part.
To return to the original question, I don't think this is either a bug or a feature but, rather, a design decision: when replacing multiple times, should $1 contain the value of the last successful match or should it be undef to reflect the fact that the last match failed? I wouldn't presume to say that the wrong choice was made but it's obvious what that choice was.
|
|---|