|P is for Practical|
Elegant examples to parse parenthesised stringsby back-n-black (Initiate)
|on May 19, 2010 at 12:04 UTC||Need Help??|
back-n-black has asked for the
wisdom of the Perl Monks concerning the following question:
I've never been that good at regular expressions. What I want to do is parse many log entries for words, ultimately, in SQL like expressions.
For example.$line = "05/04/2010 13:09:45 - A - somebody - ( ( my.my id >= 1 ) ) and ( ( is-relative.to code = 'sister' ) or ( is-relative.to code = 'brother' ) or ( is-mother.to code = 'dog' ) )";
What ultimately I need out of these strings are:
but something like this would be great!
I have been looking a while for hints to an elegant resolution for this problem. There is much dialogue about the use of Text::Balanced but not enough examples in the documentation for my little brain, to help me solve the riddle.
I have an example here that just pulls the expressions, I know what to do from there. I would like some ideas or code examples on a more elegant solution using one of the CPAN modules if that is possible.
What it basically does is:
Here is a snippet of code that pulls the expressions