|
|
| Welcome to the Monastery | |
| PerlMonks |
Using Parse::RecDescent to parse Perl-ish strings without resorting to string evalby polypompholyx (Hermit) |
| on Feb 29, 2008 at 16:32 UTC ( #671209=perlquestion: print w/ replies, xml ) | Need Help?? |
|
polypompholyx has asked for the
wisdom of the Perl Monks concerning the following question:
Dear Monks, I'm in the middle of updating a module that grades Excel spreadsheets by comparing the contents of cells to a model text file parsed by Parse::RecDescent. Strings are allowed in the comparisons, but in the previous version of the module, they were hacked in by simply returning a manually unescaped version of the matched text, e.g.:
I want to use the <perl_quotelike> production (a wrapper around Text::Balanced), for greater flexibility with quoted strings and regexes. The problem is that <perl_quotelike> extracts the Perl-ish string/regex, but the only way I can think of to interpret the string/regex correctly (which could contain quotes, backslashes, Unicode hexes, regex modifers, etc.) is to eval the relevant bits, e.g.:
Which is nasty, as the model file text could then contain:
Am I missing something, or am I trapped between either implementing my own interpolator/unescaper (which certainly won't be able to replicate all the useful features of perl quoting and regex modifiers), or using string eval (and hoping that no-one does anything nasty)?
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||