Instead of writing it as a truth table, write it as a state machine. I would translate that as follows:
- Do I have name? Y -> 2, N -> 10
- Do I have email? Y -> 3, N -> 13
- Do I have add? Y -> 4, N -> 7
- Does email exist? Y -> 5, N -> 6
- Warn that email exists
- Add email to DB
- Does email exist? Y -> 8, N -> 9
- Remove email
- Warn that email doesn't exist
- Do I have email? Y -> 11, N -> 12
- Warn that name is empty
- Warn that name and email are empty
- Warn that email is empty
Now, you want to know how to programatically do this from a data structure? Well, there are state machine modules on CPAN. I'm not going to suggest one cause I've never used them.
If you don't want to go that route, I would suggest using sub generators and a hash table of paths.
As an aside - business logic is generally much more complicated than a truth table can represent. That's why state machines (and their little cousins flowcharts) are much better. They're something both business analysts and developers can understand and analyze for correctness and completeness.
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.