http://www.perlmonks.org?node_id=929711


in reply to ${^MATCH} regex special variable(s) and /p regex modifier

Following the replies of JavaFan and lidden, I tried matching against the string 'foo 123 bar' in Strawberries 5.10.1 and 5.12.3. I found that without the /p modifier  /(123)/ and  /\d+/ 'correctly' assigned to all the  ${^MATCH} variables and  /123/ did not. (All these regexes assign as expected when the /p modifier is used.)

I guess the take-away lesson here is toolic's emphasis on the word 'guaranteed' in the documentation: it really does mean what it says. I'm of two minds about submitting a patch request for the docs. On one hand, the current documentation states simply and clearly what is guaranteed and the conditions of the guarantee. On the other hand, I have a compulsion to warn that without the protection of the /p modifier, there are situations in which the  ${^MATCH} variables may seem to work properly without, in fact, doing so reliably; i.e., one may spend the day ambling very enjoyably through the jungle, then suddenly find oneself standing in a ten foot deep hole with a five foot bamboo stake up a very sensitive place. Must think on this.