Is there a CPAN module that can read a string like this:
"[[<asdf>, <foo>], (abc, def, ghi), ({'jkl'})]"
...and parse it into some sort of tree structure that's easy to walk and pretty-print?
Is there a CPAN module that can read a string like this:
"[[<asdf>, <foo>], (abc, def, ghi), ({'jkl'})]"
...and parse it into some sort of tree structure that's easy to walk and pretty-print?
Damian Conway's Parse::RecDescent
I haven't used this, but it's a good bet that a Perl module written by Damian Conway is worth using.
If the string is identical to the Data Dumper format, then it can be eval
-ed back into the original structure.
I think that you could build on top of Text::Balanced, which will do a lot of the heavy lifting for you. You'll still need to build a tree structure, though.
Perl 6 is going to have built-in facilities to help support this. In the interim, Text::Balanced (as mentioned by Dave Rolsky) is probably the module of choice. Note that it, too, was written by Damian Conway (as commended by Bill Karwin).
Perl 5.10's regular expressions can handle balanced structures like that. See the (?PARNO) (?-PARNO) (?+PARNO) (?R) (?0)
section in perlre.