in reply to Re^2: elsif chain vs. dispatch
in thread elsif chain vs. dispatch
The slow bit is the function call, not the hash lookup which you'd also have to do with the symtab anyway. With a hash, you have better control over what inputs are allowed and how they are dispatched.
With symtab:
my $handler = do { no strict 'refs'; \&{"handle_fieldcode_$code"} }; ...handle expections somehow?... die if !$handler; $handler->(@args);
With hash;
my $handler = $lookup{$code}; die if !$handler; $handler->(@args);
with a one-time setup of
my %lookup = map { no warnings 'refs'; $_ => \&{"handle_fieldcode_$_"} } 'A'..'Z'; ...modify %lookup for expections...
|
|---|