| Next | Tricks of the Wizards | 181 |
sub run_machine {
for (;;) {
my $t_table = $machine{$STATE};
my ($input, @args) = get_input();
my ($action, $next_state) =
@{$t_table->{$input} || $t_table->{DEFAULT}};
unless defined($next_state) {
die "No transition defined for state $STATE, input $input";
}
$action->(@args) if $action;
$STATE = $next_state;
}
}
For something as complicated as NNTP, this is very simple code!
All the details are in the table, which is tidy and compact
Brian Kernighan (noted wizard) says:
Capture regularity with code, irregularity with data.
| Next | ![]() |
Copyright © 2003 M. J. Dominus |