The first two digits are the country code, the other three are the prefix of the subscribers number. This hash can contain more than 100 of these prefixes, where the prefixes are of variable length. Now I have a single phone number e.g. 31456000001. I would like to do ONE lookup in the hash to find that value corresponding with this prefix (31456, which is 2). But the problem is that the prefixes have a random length as you can see in the hash, so I cannot use the first 5 digits of the phonenumber as the key. It would be nice to specify a *-sign to use as a wildcard in the hash, e.g.:%hash = (31123 => 1, 31456 => 2, 32123 => 3, 32456 => 4, 33 => 5, 3361 => 6, ... );
where %hash->{33000000000} would give me 5. Is there a way to accomplish this with only ONE lookup instead of using a regexp on all keys in the array? TIA! Regards, Marcel%hash = (31123 => 1, 31456 => 2, 32123 => 3, 32456 => 4, 33* => 5, 3361* => 6, ... );
In reply to Fast lookup for prefixes in hash by Marcello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |