develooper Front page | perl.fwp | Postings from August 2009

Fw: Help with regex

Thread Next
From:
Andy_Bach
Date:
August 13, 2009 09:58
Subject:
Fw: Help with regex
Message ID:
OF16688216.B39359B3-ON86257611.005D2AF7-86257611.005D31E7@uscmail.uscourts.gov
Seems like this could be fun/golf

----- Forwarded by Andy Bach/WIWB/07/USCOURTS on 08/13/2009 11:57 AM -----


I am using Active Perl 5.8.8. and Perl Dev Kit 7.0.
 
I'm writing some code that standardizes the format of phone numbers in a
database because users have entered them in every way imaginable.

Anyway, some of the phone numbers look like this:
 
  800-69-VORTEX
 
...where the user has entered alpha characters instead of numbers. My
first thought was to use a hash to do the translation, like this:
 
  %alpha2num =
  (
    'A' => '2',
    'B' => '2',
    'C' => '2',
    'D' => '3',
    .
    .
    .

...but since the rest of the routine uses only regular expressions, I
thought that it would be nice if this type of translation could be
accomplished with a regex.

I have not been able to think of a way, but I thought I would put it to
the list to see if anyone else has done this before.

Barry Brevik
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About