in reply to How do I split a string on highly structured/nested data?
One approach is to use a parser like
Parse::RecDescent. A real parser
(as opposed to parsing a string with a regular
expression alone) is much more powerful and
can be more apropriate for parsing highly
structured/nested data like your example.
For other approaches see the discussion on Balancing Parens.use Parse::RecDescent; my $teststr="a,b,op2(c,d),op3(e,op4(f,g))"; my $grammar = q { content: /[^\)\(\,]+/ function: content '(' list ')' value: content item: function | value list: item ',' list | item startrule: list }; my $parser = new Parse::RecDescent ($grammar) or die "Bad grammar!\n"; defined $parser->startrule($teststr) or print "Bad text!\n";
|
---|
In Section
Seekers of Perl Wisdom