Evaluating user-defined conditions
Paul "LeoNerd" Evans
leonerd at leonerd.org.uk
Mon Jun 9 13:45:49 BST 2014
On Mon, 9 Jun 2014 13:10:35 +0100
James Laver <james.laver at gmail.com> wrote:
> In short, if you trust the input, just eval() it, and if you don’t,
> you want a parser.
>
> You might consider transforming it automatically into postfix
> notation and building a really simple stack machine if you just want
> basic arithmetic and placeholders. Otherwise, I can recommend
> Parse::RecDescent.
Parser::MGC will also let you build quite a simple expression evaluator.
For example, see this one that just does +-*/ on integers:
https://metacpan.org/source/PEVANS/Parser-MGC-0.12/examples/eval-expr.pl
--
Paul "LeoNerd" Evans
leonerd at leonerd.org.uk
http://www.leonerd.org.uk/ | https://metacpan.org/author/PEVANS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20140609/88966ac9/signature.pgp
More information about the london.pm
mailing list