Just another Perl shrine | |
PerlMonks |
/g matches not really global in scalar context!by blazar (Canon) |
on Nov 14, 2005 at 11:42 UTC ( [id://508283]=perlmeditation: print w/replies, xml ) | Need Help?? |
In a private mail exchange with a friend, talking about Perl, he wrote "aiutino" (long story, Italian monks will understand!) at which point I replied with Now I know that the extended regex (?{ code }) feature is still deemed experimental. But I really wanted to use it both for the sake of illustrating it and because IMHO it strongly stresses the idea that each use of the "incriminated" word is strictly associated with the emission of an "Argh!" warning. To be sure, before sending the mail, I tried the code, and much to my surprise only one warning was emitted even if a line contained more instances of "aiutino". So I tried instead, and it did work as expected. Now it seems that the /g modifier on the match operator doesn't make it really global in scalar (or void) context, which could be because of an optimization effect, since for ordinary matches it doesn't really make a difference. Indeed in quite a few years of Perl programming, I had never realized this was the case. But! if one deliberately specifies the /g modifier even in scalar context, then he should get what that it promises, and be them as experimental as you like, extended regex features executing code may be a good reason to guarantee it. Any thoughts?
Back to
Meditations
|
|