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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; }

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found