http://www.perlmonks.org?node_id=241671

robartes has asked for the wisdom of the Perl Monks concerning the following question:

I'm about to write a script to parse a log file and I'm looking for modules that implement a state machine. The log file in question is for a process that feeds user information from an MQ Series queue into an LDAP server. This process follows a well defined series of steps, with a few branches along the way (e.g. new record found -> user does not exist in LDAP -> adding user to LDAP -> adding extra user information to LDAP -> done). Because of this structure, I though a small state machine would be the best way of dealing with this log file.

Looking around, I found Bio::Tools::StateMachine::AbstractStateMachine, which seems like a good solution, and POE which, with a bit of imagination, can be used to do the job. Before I decide on either of these, however, I thought I'd ask around whether anyone has already done something like this or whether anyone knows of any other state machine modules.

Or, if you think an other way of doing this is better, I'd appreciate any input on that as well.

Thanks!

CU
Robartes-

Replies are listed 'Best First'.
•Re: Looking for a state machine
by merlyn (Sage) on Mar 10, 2003 at 13:18 UTC
Re: Looking for a state machine
by valdez (Monsignor) on Mar 10, 2003 at 08:23 UTC

    There are also some modules in the DFA namespace.

    Ciao, Valerio

Re: Looking for a state machine
by eduardo (Curate) on Mar 10, 2003 at 17:29 UTC
    Now, I have been warned by our own local celebrity merlyn that you have to be wary of turning into "every problem looks like a nail to me with my new shiny hammer" guy. However, I have to admit that lately, 99% of the code that I've written I've been decomposing into state machines, and using POE as my "framework of choice." Though I definetly agree that if you can parse it using thedamian's lovely Parse::RecDescent you probably should give that a whack, I've had lovely luck here as of late following a simple methodology.
    1. Break down problem into discrete states
    2. Define transitions between those states
    3. Implement states as a POE::Session
    4. Set up driver for dataflow as entry point into POE (in this case get the file pumping into the POE system)
    5. Lean back and enjoy your productivity
    I understand that POE is best suited for "interesting parallel problems", but I've learned that it's helped me with my thought process when it comes to defining state-machine(ish) problems. The only problem with POE is that it does have a rather high "barrier of entry" the first and second time you use it (it did for me), so if this is a problem on a timetable, you may not want to attack it with this particular hammer. If you do however, I can suggest no better starting point than merlyn's excellent Linux Magazine column... here...
regexps and lexers.
by zby (Vicar) on Mar 10, 2003 at 08:38 UTC
    When you say State Machines immidiately my mind reacts with regular expressions (through the equivalence of regexps and DFA). I know it's not quite adequate in this case, but there is that experimental (?{code}) pattern in regexps (and with Perl 6 this should be much more basic technique).

    Another possibillity are lexical analyzers like Parse::Lex.