in reply to Re: The 'g' modifier in compiled regex
in thread The 'g' modifier in compiled regex
Well, I am aware of this issue. I was wrong about wondering whether /g was for substitution or for matching. I was wrong because /g is for both, for the action (as also pointed out by japhy), but I never thought that /g was for the regex.
When you said xism are toggles, I looked again at perlre and there under "(?imsx-imsx)" entry it says, "One or more embedded pattern-match modifiers, to be turned on (or turned off, if preceded by "-")". I should have thought that they were toggles in the first place if I read more carefully earlier. Thanks for this :-) But in this case, /g is also a toggle for the normal m// or s///, right?
Notice how the s doesn't affect the (?:...), only what's in it? That means $re = qr/.../g; @matches = /$re/; makes no sense since part of the regexp doesn't loop ((?:...)) and part of it does (...). Again, we'd need to do $re = qr/.../g; @matches = /$re/g;, gaining nothing.
Well, that's for the current implementation. But, what if I *know* that I will use the qr/pat/g in list context for the rest of the code? And when I use it in scalar context then it's my fault. If /g is allowed in qr//, it will surely be accompanied by a note something like "only use it in list context, otherwise there will be mandatory warning your code will be ignored", or even, "..., otherwise it's compilation error".
I don't dive into the source code or the p5p archive. I don't know how exactly the regex precompilation is implemented, or how it will be affected should /g is implemented in the precompiled regex (if it's possible at all). Now, you just tempted me to sense the tendention to request this feature: allow global matching modifier in the qr// so it will always match globally whenever that compiled regex is used. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: The 'g' modifier in compiled regex
by rodion (Chaplain) on Apr 09, 2007 at 09:28 UTC | |
by exussum0 (Vicar) on Apr 09, 2007 at 15:01 UTC | |
|
Re^3: The 'g' modifier in compiled regex
by demerphq (Chancellor) on Apr 09, 2007 at 16:56 UTC |