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.
See if this one liner puts you on the right track:
perl -e '$line = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $line =~ tr/ABCDEFGHIJKLMNOPQRSTUVWXYZ/22233333355566677778889999/; print "$line\n"'
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>