Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: When should I use a dispatch table?

by Limbic~Region (Chancellor)
on Nov 30, 2006 at 23:46 UTC ( #587082=note: print w/ replies, xml ) Need Help??


in reply to Re: When should I use a dispatch table?
in thread When should I use a dispatch table?

traveler,
The values are integers only because it made enumerating easier. The string equality is intentional. The 1 .. n could have as easily been 'a' .. 'z'.

The testing for the hash key existance is necessary sometimes (default condition). The template didn't discriminate and always added it. Thanks to your keen eye, it has been fixed. It did not change the results that much with or without default conditions.

Cheers - L~R


Comment on Re^2: When should I use a dispatch table?
Re^3: When should I use a dispatch table?
by traveler (Parson) on Nov 30, 2006 at 23:53 UTC
    The values are integers only because it made enumerating easier. The string equality is intentional. The 1 .. n could have as easily been 'a' .. 'z'.

    OK. But doesn't that make the ifelse code slower because it has to stringify and/or do string comparison, while the hash can do an integer comparison?

    I did try another test. Since the values were integers I replaced the dispatch table hash with an array and performance improved, but not enough to catch the ifelse. I am still quite confused.

      traveler,
      Stringification happens both in the hash table and in the if/elsif equality test so it is fair. The eq forces string context and so do hash keys. Anyone that has tried to use a reference as a hash key can attest to that.

      Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-07-13 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls