Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Clubbing array elements together:

by sundialsvc4 (Monsignor)
on Jan 29, 2013 at 13:28 UTC ( #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.


Comment on Re: Clubbing array elements together:
Re^2: Clubbing array elements together:
by karlgoethebier (Curate) 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
Node Status?
node history
Node Type: note [id://1015873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-09-18 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls