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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||