[Dub-pm] Phone numbers
Fergal Daly
fergal at esatclear.ie
Tue Oct 19 10:00:30 CDT 2004
On Tue, Oct 19, 2004 at 03:21:29PM +0100, David Cantrell wrote:
> On Tue, Oct 19, 2004 at 02:36:32PM +0100, Dermot McNally wrote:
>
> > What the other folks said about 048, stands, but there's a snag trying
> > to incorporate enough clevers to handle this into
> > Number::Phone::Country. The lookup expects the number you provide to be
> > in full international format. Arguably, the number +353-48-12345678 is
> > only a pseudo-international number, as I'm not sure if you can dial it
> > from anywhere outside ROI.
>
> I'll have to try it. Anyone got a company in the north that they
> particularly hate and whose time I can waste trying it out? :-)
>
> > What are you planning? To have numbers of that format as well as the
> > +44-28-12345678 equivalent map to a mock-ISO code for NI?
>
> Look at the source for N::P::Country, and how he handles the craziness
> that is +1. I'd handle +353 the same way. And +7, +34, and +39.
That certainly does look crazy.
I did this a few years ago and I did what you're doing, see if the whole
number matches, then chop off the last number and try again, then chop off
and try again... I also tried building a trie (although I didn't know it at
the time).
If you have the following prefixes
12 = GB
13 = IT
121 = IE
245 = CA
your trie looks like
1
- 2 = GB
- 1 = IE
- 3 = IT
2
- 4
- 5 = CA
and say the number 1278453434 comes along. Then you try to go into 1, which
succeeds, then you try to go into the 2 branch of 1 which succeeds, then you
try to go into the 7 branch of 2 which doesn't succeed because there is no 7
branch so you're finished and the matching prefix is 12 and the country code
is GB.
You can actually do all this with a regex and a hash. For the above, the
regex is
/^(121|12|13|245)/
the key is that the longer prefix comes before the shorter prefix. If you
want more efficiency you can make this
/^(1(?:2(?:1?)|3)|245)/
Obviously you don't want to go generating them by hand but once you've got
it, it's very nippy. I know someone working for a telco who implemented his
tries in C which was much more efficient, time and space-wise but he can't
release the code,
F
More information about the Dublin-pm
mailing list