On Thu, Aug 13, 2009 at 12:58 PM, <andy_b...@wiwb.uscourts.gov> wrote:
> 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.

$phone =~ s/([A-Za-z])/$alpha2num{"\U$1"}/g;

Also handles the case of 650-Mr-Plow

-- Adam

Reply via email to