Hi Dear Perl Experts,

I got a problem about how to represent a complex data structure in perl. Here is a rough introduction of my data: (1) the data consist of several commands: cmd00, cmd01, cmd02... And each command has a respective table; (2) the table has 3 elements: initial state, feedback and end state; (3) initial state could be any subset of {idle, start, jump, halt}; for each initial state, feedback has to pick up one from number (0 .. 3); (4) each initial state and feedback have a certain relative end state which is also within {idle, start, jump, halt}; end state could be more than one elements;

Graphically and strictly, it is showed as below:
Command              Initial state.           Feedback.              E +nd state cmd00.                    Idle                      0.                 +            Idle or start                                                             1.         +                    Start                                 Start.                   0.           +                  Jump                                                             3.         +                    Halt or start                                                             2.         +                     Idle cmd01                     Idle                      0.                 +            Idle or start                                                             1.         +                    Jump                                 Jump                   0.             +                Halt or idle                                                             1.         +                    start                                                             2.         +                     Idle cmd02.  ....... ......

My target: I need a function like sub get_endstate_by_cmd($cmd, $default_state); I will send a random sequence of commands to the sub routine in which initial state and feedback will be randomized in their legal range, then it returns the end state for next iteration. The difficulties are: 1. To represent the data; 2. To randomize in a legal range; Could anyone give me some hints?


In reply to How to represent complex data structure and manipulate it easily? by Hanken

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, details, 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, summary, 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.