note
sundialsvc4
<p>
I prefer to solve such problems using a <em>[http://en.wikipedia.org/wiki/Finite-state_machine|Finite-State Machine (FSM)]</em> algorithm, because it represents a generalized and easily-adaptable approach to the problem.
</p><p>
For example, from an <tt>initial</tt> state (that is to say, “while not in <tt>final</tt> 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 <tt>final, skip_blanks,</tt> or <tt>first_string</tt>. 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.
</p><p>
Since the FSM graph can be tricky to correctly design, I suggest that you build a test-suite using <i>e.g.</i> [mod://Test::Most] to prove that it works as intended in all cases.
</p>
1015855
1015855