Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

I have a program where I need to check to see if a variable is equal to any one of a list of 1000+ values. Since I'll need to check this several times over the course of the program's execution, I'm wonder what the most efficient way to do this is.

My first though is to read all 1000+ of these values into a hash on startup (there is no DB backing this) where the values I'm checking against are the keys and then just using something like 1 for the value. Then when I need to do a see if the variable is one of these values, just check the hash using the current value of the variable as the key and see if I get anything "true" back...

Sound like I'm on the right track? Or is there a "better" way?

In reply to How to check if a variable's value is equal to a member of a list of values by cls33

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2014-07-12 17:56 GMT
    Find Nodes?
      Voting Booth?

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

      Results (240 votes), past polls