http://www.perlmonks.org?node_id=686291


in reply to Generate a truth table from input string

Quick&dirty solution:

Use a regualr expression to extract all the variables (assuming a form of \w+), store them in an hash along with an auto-generated variable name (eg $a,$b..).

Use another regexp to replace all variables with the new names and replace the operators with the corresponding perl operator (eg s/\*/ && /g).

Perform a series of nested loops, one for each variable, and eval the expression.

Note that this is probably not what your teacher wants from you!

Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.