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


in reply to Re^5: Generate a truth table from input string
in thread Generate a truth table from input string

For your viewing pleasure.....

while(<DATA>){ my ($re, $term, @vars, %vars, $loops); s/\*/ && /g; s/\+/ || /g; s/(\w+)\s*'/!$1/g; $re = qr{\((?:(?>[^()]+)|(??{$re}))*\)}; # :-) s/($re)\s*'/!$1/g; $term = $_; @vars = $_ =~ m/(\w+)/g; $vars{$_}++ for @vars; @vars = sort keys %vars; s/(\w+)/\$$1/g; printf "\n@vars = $term"; @vars = map {"\$$_"}@vars; $loops .= "for $_ (0..1) {\n" for @vars; $loops .= qq{printf "@vars = %d\n", eval;\n}; $loops .= "}" for @vars; do{ no strict 'vars'; eval $loops }; die "Can't process $term$_\n$@\n" if $@; } __DATA__ a*b*!(c) a'+b'+c' !(a*b) b^a (a^b)' (a+(a+b))'*c