talexb has asked for the wisdom of the Perl Monks concerning the following question:
This is interesting (to me). I'm cleaning up some JSON so that it's palatable to the API I'm using, and I'm discovering some unexpected behaviour.
I'm expecting this regexp to insert spaces after all occurrences of left square bracket, colon and left brace. The result:$foo = ':{"' $foo =~ s/([:,{])(.)/$1 $2/g; print "'$foo'\n";
If I run the regexp again, I finally get the result I'm expecting:': {"'
That's counter-intuitive to me .. if I put 'g' at the end of a regexp, I expect it to run that expression repeatedly (flashback to COBOL .. REPEAT UNTIL DONE).': { "'
Thoughts?
|
---|
Back to
Seekers of Perl Wisdom