Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Generate a truth table from input string

by psini (Deacon)
on May 13, 2008 at 15:09 UTC ( #686291=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://686291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-06-20 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (95 votes). Check out past polls.

    Notices?