Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Answer: How do I break down a phone number and rebuild it?

by Fastolfe (Vicar)
on Nov 18, 2000 at 03:53 UTC ( [id://42306]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I break down a phone number and rebuild it?
in thread How do I parse a telephone number?

I might have tried to generalize that even further, though you still have regional issues to worry about. I.e. this won't work for everyone:
@FORMAT_PHONE = ( '%d%d%d', # 911 '%d-%d%d%d', # 1-411 '%d-%d%d%d%d', # 5-1212 ? '%d%d-%d%d%d%d', # 55-1212 ? '%d%d%d-%d%d%d%d', # 555-1212 '%d-%d%d%d-%d%d%d%d', # 1-222-2345 '%d%d%d-%d%d%d-%d%d%d', # 212-114-151 ? '(%d%d%d) %d%d%d-%d%d%d%d', # (800) 555-1212 '+%d (%d%d%d) %d%d%d-%d%d%d%d', # +1 (800) 555-1212 '+%d%d (%d%d%d) %d%d%d-%d%d%d%d', # +01 (800) 555-1212 '+%d%d%d (%d%d%d) %d%d%d-%d%d%d%d', # +011 (800) 555-1212 '+%d%d%d %d (%d%d%d) %d%d%d-%d%d%d%d', # +011 1 (800) 555-1212 '%d%d%d%d%d (%d%d%d) %d%d%d-%d%d%d%d', # 10321 (800) 555-1212 '%d%d%d%d%d %d (%d%d%d) %d%d%d-%d%d%d%d', # 10321 1 (800) 555-1212 '%d%d%d%d-%d%d%d (%d%d%d) %d%d%d-%d%d%d%d', # 1010-220 (800) 555-12 +12 '%d%d%d%d-%d%d%d %d (%d%d%d) %d%d%d-%d%d%d%d', # 1010-220 1 (800) 5 +55-1212 # etc... ); my %L2M; @L2M{qw: Q Z :} = 1; @L2M{qw: A B C :} = 2; @L2M{qw: D E F :} = 3; @L2M{qw: G H I :} = 4; @L2M{qw: J K L :} = 5; @L2M{qw: M N O :} = 6; @L2M{qw: P R S :} = 7; # some define this as PQRS @L2M{qw: T U V :} = 8; @L2M{qw: W X Y :} = 9; # some define this as WXYZ sub format_phone { my $number = shift; $number =~ s/[a-zA-Z]/$L2M{uc($1)}/eg; $number =~ s/\D//g; # maybe allow # and * later?? if (defined($FORMAT_PHONE[length($number)-3])) { return sprintf($FORMAT_PHONE[length($number)-3], split(//, $numb +er)); } return; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://42306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found