Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Instead of writing it as a truth table, write it as a state machine. I would translate that as follows:
  1. Do I have name? Y -> 2, N -> 10
  2. Do I have email? Y -> 3, N -> 13
  3. Do I have add? Y -> 4, N -> 7
  4. Does email exist? Y -> 5, N -> 6
  5. Warn that email exists
  6. Add email to DB
  7. Does email exist? Y -> 8, N -> 9
  8. Remove email
  9. Warn that email doesn't exist
  10. Do I have email? Y -> 11, N -> 12
  11. Warn that name is empty
  12. Warn that name and email are empty
  13. 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.


In reply to Re: Code generation from truth table. by dragonchild
in thread Code generation from truth table. by artist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (4)
    As of 2021-03-02 18:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favorite kind of desktop background is:











      Results (57 votes). Check out past polls.

      Notices?