Re: unexpected behaviour of text::balancedby roboticus (Chancellor)
|on Nov 24, 2012 at 13:41 UTC||Need Help??|
That was surprising. It appears that Text::Balanced alters some of the magic innards of the variable. I changed your code a bit:
And get the desired results. The funny thing is, I was expecting that $data would be empty after the call or something, but was surprised to see that the value looked unchanged. I then changed the second extract_multiple to:
and it worked as you expect. I haven't read the Text::Balanced docs to see if it's expected behaviour or not. But if it isn't, you may want to file a bug report on it.
Update: I remember a module (Devel::Peek) that lets you look at the magic goo inside of variables, so I changed your program to look at the $data variable before and after the call:
After seeing this, I reviewed the docs for Text::Balanced, and noticed this:
Note that in a list context, the contents of the original input text (the first argument) are not modified in any way. However, if the input text was passed in a variable, that variable's pos value is updated to point at the first character after the extracted text. That means that in a list context the various subroutines can be used much like regular expressions. For example:
In short, it's supposed to do that. That way it's ready to pull out the *next* bits of balanced text for you. Appending a null to the end of the string simply resets the string.
Sigh! Had I read the docs before playing with the code, I'd've saved myself a little time. Ah, well...
When your only tool is a hammer, all problems look like your thumb.