in reply to Howto avoid large hard-coded else-if function calls

I think a dispatch table will rapidly become unwieldy if you need to consider all possible function call combinations of A, B, C, D and E. Assuming A must always be called first, and C must be called between B and D (if present), and so on, you are looking at the power set of A .. E. And the size of the power set of a set increases exponentially.

Here's all the different ways you can call functions A to E:

perl -MData::PowerSet -le 'my $p = Data::PowerSet->new(qw(A B C D E)); + print "@$_" while $_= $p->next' # produces : A B C D E B C D E A C D E C D E A B D E B D E A D E D E A B C E B C E A C E C E A B E B E A E E A B C D B C D A C D C D A B D B D A D D A B C B C A C C A B B A

Add three more function and the size of your dispatch table grows to 256 entries... and it gets much worse if you can call any of A to E in any order.

I think it would be much better to just split your 'ABC' input into separate characters, and use a simple dispatch to deal with the five (or more) elementary cases:

my %dispatch = ( A => \&func_a, B => \&func_b, C => \&func_c, D => \&func_d, E => \&func_e, ); for my $token (split //, $func_com) { push @all_res, [$dispatch{$token}->(@some_val)]; }

This way it is as trivial to deal with 'ABC', 'AD', 'BCE' as it is to deal with 'AABD' or 'BEAD'.

• another intruder with the mooring in the heart of the Perl