Evaluating user-defined conditions

Andrew Beverley andy at andybev.com
Mon Jun 9 11:36:30 BST 2014


Dear all,

I'd like to take a condition specified by a user and use it to perform a
set of tests on a data set. Is there a module to do this?

For example, I might have an array of hashes containing "name", "price"
and "age". I would like a user to be able to define their own condition,
such as "age > 10 && price < (age + 5) * 10", and then to get the result
(true or false) for each of the array items.

Is there a nice easy way to do this without trying to parse the
condition myself? Presumably I could do some sort of eval, but that
sounds highly dangerous with user input ;-)

Andy




More information about the london.pm mailing list