There's more than one way to do things | |
PerlMonks |
Re: Text parsing. Processing scopes and subscopes.by nuance (Hermit) |
on Aug 26, 2015 at 13:35 UTC ( [id://1140020]=note: print w/replies, xml ) | Need Help?? |
The best advice already given is use a template module. If you decide not to, I'd use substr rather than regular expressions You can use index to find closing braces, the first one you find will be the close of the innermost scope. Then use the position you found with rindex to find the opening brace of that scope. You can extract the data with substr. You can process the extract and then use substr to replace it and the braces in the original data. Instead of processing the extract and replacing it, this snippet uses substr to replace the braces. This means you won't continually work on the same scope. It prints the bits it extracted as $extract so you can see it works on scopes in the correct order. You need to make sure that whatever you substitute in doesn't have braces. Output
Nuance
In Section
Seekers of Perl Wisdom
|
|