in reply to Conditions and Function call
A few comments (in no particular order)
Before I give alternatives, I'm going to make a few assumptions:
Some options:
while (1) { my %options = discover_my_options(); next unless $options{ma} && $options{sy}; if ($options{a1}) { do_a1(); next; } if ($options{tr}) { do_tr(); next; } if ($options{ge}) { do_ge(); next; } }
my %dispatch_table = ( a1 => \&do_a1, tr => \&do_ge, ge => \&do_tr, ); while (1) { my ($skip_iteration, $value) = discover_my_options(); next if $skip_iteration; my $function = $dispatch_table{$value} || next; $function->(); }
The first is a cleanup of your existing the code. The second is a way of parameterizing function calls. This isn't something only Perl can do. MUD code has been doing this since the late 80's, and that was (usually) written in C, using funcp's.
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|