Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: looking for a good idiom: return this if this is trueby mstone (Deacon) |
on Mar 05, 2005 at 22:08 UTC ( [id://436964]=note: print w/replies, xml ) | Need Help?? |
First of all, it helps to characterize the problem: you're building a very simple state machine. Each called subroutine is a new state, and the return value from each called function is the input which selects the next transition. In this case, you want FALSE to trigger a transition to the next state, and TRUE to trigger a transition to the accept state:
In this case, you can implement that with a list of function pointers and a loop:
And more generally, you can use a hash as a transition table:
which allows for multiple output values per function, and state diagrams that are more complicated than just a simple list. If you want to pass parameters to the functions, pass a listref and have the called functions and use it as an argument list, a stack, a queue, or whatever:
In Section
Seekers of Perl Wisdom
|
|