Marcello has asked for the wisdom of the Perl Monks concerning the following question:
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, ... );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fast lookup for prefixes in hash
by mirod (Canon) on Oct 31, 2001 at 18:23 UTC | |
|
Re: Fast lookup for prefixes in hash
by Zaxo (Archbishop) on Oct 31, 2001 at 21:18 UTC | |
|
Re: Fast lookup for prefixes in hash
by japhy (Canon) on Oct 31, 2001 at 20:15 UTC | |
by tye (Sage) on Oct 31, 2001 at 21:05 UTC | |
by japhy (Canon) on Oct 31, 2001 at 21:12 UTC | |
by tilly (Archbishop) on Oct 31, 2001 at 22:06 UTC | |
by japhy (Canon) on Oct 31, 2001 at 22:15 UTC | |
|
Re: Fast lookup for prefixes in hash
by Masem (Monsignor) on Oct 31, 2001 at 18:27 UTC | |
|
Re: Fast lookup for prefixes in hash
by jryan (Vicar) on Oct 31, 2001 at 21:41 UTC | |
|
Re: Fast lookup for prefixes in hash
by Fastolfe (Vicar) on Nov 01, 2001 at 06:01 UTC | |
|
Re: Fast lookup for prefixes in hash
by runrig (Abbot) on Nov 01, 2001 at 08:05 UTC |