A more generalized way to handle such requirements is with a Finite-State Machine (FSM) approach.
The algorithms consider, not only the current line of input, but the $state that the FSM is “in” at the time,
where the current value of $state is determined by recent history of lines seen.
Sounds cool. I found a lot of interesting hits using Super Search:
- Re: Comparing two hashes-help: "I often find it useful to describe logic like this in terms of a finite-state machine (FSM)"
- Re: Spliting file + removing column: "For this, I use “finite-state machine (FSM)” logic"
- Re: ADSI groups users: "I naturally look at such problems with an eye toward so-called finite state machine logic"
- Re: IO::Socket client does not detect when server network connection dies: "Logic like this is sometimes well designed using Finite State-Machine (FSM) logic"
- Wisdom on how to build a "stressful simulation test" with Selenium & POE: "Each actor is basically an individual finite-state machine"
- Re: A way to avoid repeated conditional loops: "Call it “a flag variable” if you want to, but this is a classic place for a finite-state machine (FSM) algorithm"
- Re: Perl/Tk code structure: "A typical design for the shepherd process is a Finite-State Machine (FSM), or more likely, two FSMs"
- Re: how did blocking IO become such a problem?: "The entire life cycle of a request, and much of the outer request-handling heuristics, is most easily described using a finite-state machine (FSM) algorithm"
- Re: Clubbing array elements together:: "I prefer to solve such problems using a Finite-State Machine (FSM) algorithm"
- Re: File Find/Replace with the replacement coming from part of earlier matched string: "This is an absolutely classic case for a “finite-state machine (FSM)” algorithm"
- Re: How to check if successfully logged in?: "it must be a finite-state machine (FSM) design, because in the final analysis the host web-site is driving the bus ... Fact of the matter is, a production mechanize-script is often two FSMs"
- Re: Reading concurrently two files with different number of lines: "It might be useful for you to look at the concept of Finite-State Machine (FSM) algorithms as a source of ideas for generalized solutions to these problems"
- Re: RFC: Simulating Ruby's "yield" and "blocks" in Perl: "these can be used to implement finite-state machines (FSMs)"
- Re: Selecting HL7 Transactions: "this sort of thing is most-easily handled by finite-state machine (FSM) techniques"
- Re^2: Too much recursion: "For dealing with very complicated inputs, the notion of a Finite-State Machine (FSM) can be useful"
- Re: Sorting through a file with multiple tables and extracting data: "The general approach is that of a finite-state machine (FSM)"
- Re: Is this a simple, robust, and maintainable design?: "sounds like a Finite-state machine. If you haven't coded a finite state machine in Perl before, this article may be helpful."
All these glowing endorsements have got me excited, yet I couldn't
find any sample code in any of these nodes.
So I was wondering if you could
post some of the excellent FSM code you've
implemented over the years?
It would really help me to better understand FSMs.
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- 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
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||