#!/usr/bin/perl -w exec "perldoc $0" unless @ARGV; $_ = shift; $, = " "; s/([a-z]+)/\$$1/ig; @a{/(\$\w+)/g} = 1; @v = sort keys %a; ($t="@v | $_") =~ s/\$//g; s/<=>/==/g; s/=>/<=/g; ($l=$t) =~ s/./-/g; print "\n\t$t\n\t$l\n"; eval join "",(map{"for $_ (0,1){"}@v),"print \"\\t@v | \",((",$_,")?1:0),\"\\n\"","}"x@v, "\n"; print "\n"; =head1 ttable - Print truth table of a logical proposition Prints the truth table of a logical proposition in which variable names consist of any number of consecutive letters, true is 1, false is 0, and operators are Not ! And && Or || in that order of precedence. You may also use Then => Iff <=> B. =head2 EXAMPLES >> ttable 'A && (B || A)' A B | A && (B || A) --------------------- 0 0 | 0 0 1 | 0 1 0 | 1 1 1 | 1 >> ttable '(B && (B || A)) <=> B' A B | (B && (B || A)) <=> B ----------------------------- 0 0 | 1 0 1 | 1 1 0 | 1 1 1 | 1 =head1 AUTHOR Etienne Grossmann Eetienne@cs.uky.eduE If you have never seen unreadable code, read this program's. =cut