Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: elsif chain vs. dispatch

by ikegami (Pope)
on Apr 27, 2009 at 02:57 UTC ( #760243=note: print w/ replies, xml ) Need Help??


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...


Comment on Re^3: elsif chain vs. dispatch
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://760243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2015-07-03 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (54 votes), past polls