You could do it with a mathematical operation based on the ASCII value...course that's 
not a regex.


-Tom Kinzer


-----Original Message-----
From: Kevin Old <[EMAIL PROTECTED]>
Sent: Jan 2, 2004 8:26 AM
To: [EMAIL PROTECTED]
Subject: Convert letter to phone keypad equivalent

Hello everyone,

Here's a script I wrote to convert letters into their telephone keypad
equivalents....example....A-B to 2, D-F to 3, etc.

#!/usr/bin/perl

use warnings;
use strict;

my $cnum = 'SM1550';

$cnum =~ s/[A-C]/2/g;
$cnum =~ s/[D-F]/3/g;
$cnum =~ s/[G-I]/4/g;
$cnum =~ s/[J-L]/5/g;
$cnum =~ s/[M-O]/6/g;
$cnum =~ s/[P-S]/7/g;
$cnum =~ s/[T-V]/8/g;
$cnum =~ s/[W-Y]/9/g;

print "$cnum\n"

This works like a charm, but I wondered if anyone knew of a way to
consolidate this into fewer regex's.  Like my post earlier this week,
I'm not trying to be lazy, just trying to learn other ways of
programming/consolidating regexes.

Any help is appreciated,
Kevin
-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to