Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Clubbing array elements together:

by sundialsvc4 (Abbot)
on Jan 29, 2013 at 13:28 UTC ( [id://1015873]=note: print w/replies, xml ) Need Help??


in reply to Clubbing array elements together:

I prefer to solve such problems using a Finite-State Machine (FSM) algorithm, because it represents a generalized and easily-adaptable approach to the problem.

For example, from an initial state (that is to say, “while not in final state ...”), you read a line and have one of three possibilities:   end-of-file, a blank string, or not-all-blanks.   That would lead to final, skip_blanks, or first_string.   And so on.   The FSM can be drawn out on a piece of paper as the WikiPedia article describes.   When you determine (on paper) that the graph is entirely correct, the programming is a snap.

Since the FSM graph can be tricky to correctly design, I suggest that you build a test-suite using e.g. Test::Most to prove that it works as intended in all cases.

    Replies are listed 'Best First'.
    Re^2: Clubbing array elements together:
    by karlgoethebier (Abbot) on Jan 29, 2013 at 20:17 UTC

      sundialsvc4:

      "I prefer to solve such problems using a Finite-State Machine (FSM) algorithm, because it represents a generalized and easily-adaptable approach to the problem."

      Sounds really cool. I'd like very much to see how you code it.

      Thanks in advance for advice and best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

    Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2024-04-19 16:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found